Esempio n. 1
0
        TextBlock LoadEngineConfig()
        {
            string fileName = VirtualFileSystem.GetRealPathByVirtual("user:Configs/Engine.config");
            string error;

            return(TextBlockUtils.LoadFromRealFile(fileName, out error));
        }
Esempio n. 2
0
        private void cbxVariantList_SelectedIndexChange(ListBox sender)
        {
            if (sender.SelectedItem == null)
            {
                return;
            }

            string varFilePath = string.Format("{0}\\Variants\\{1}\\{2}", VirtualFileSystem.UserDirectoryPath,
                                               spawner.Spawned.Type.Name, sender.SelectedItem.ToString());

            string    error;
            TextBlock varFile = TextBlockUtils.LoadFromRealFile(varFilePath, out error);

            if (!string.IsNullOrEmpty(error))
            {
                Log.Error(error);
                return;
            }

            if (varFile != null)
            {
                AKunit u = spawner.Spawned as AKunit;
                u.SetVariant(varFile);
            }
        }
Esempio n. 3
0
        private List <ArchiveManager.ClassB> C()
        {
            List <ArchiveManager.ClassB> list = new List <ArchiveManager.ClassB>();

            foreach (ArchiveFactory current in this.S)
            {
                string[] files = Directory.GetFiles(VirtualFileSystem.ResourceDirectoryPath, "*." + current.FileExtension, SearchOption.AllDirectories);
                string[] array = files;
                for (int i = 0; i < array.Length; i++)
                {
                    string text = array[i];
                    string path = Path.ChangeExtension(text, ".archive");
                    if (File.Exists(path))
                    {
                        TextBlock textBlock = TextBlockUtils.LoadFromRealFile(path);
                        if (textBlock != null)
                        {
                            ArchiveManager.ClassB b = new ArchiveManager.ClassB();
                            b.Factory            = current;
                            b.SourceRealFileName = text;
                            if (textBlock.IsAttributeExist("loadingPriority"))
                            {
                                b.LoadingPriority = float.Parse(textBlock.GetAttribute("loadingPriority"));
                            }
                            list.Add(b);
                        }
                    }
                }
            }
            List <ArchiveManager.ClassB> arg_FA_0 = list;

            if (ArchiveManager.U == null)
            {
                ArchiveManager.U = new Comparison <ArchiveManager.ClassB>(ArchiveManager.A);
            }
            ArchiveManager.A <ArchiveManager.ClassB>(arg_FA_0, ArchiveManager.U);
            return(list);
        }
Esempio n. 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //Engine.config parameters
            string renderingSystemComponentName = "";
            bool   allowShaders          = true;
            bool   depthBufferAccess     = true;
            string fullSceneAntialiasing = "";

            RendererWorld.FilteringModes filtering = RendererWorld.FilteringModes.RecommendedSetting;
            string renderTechnique             = "";
            bool   fullScreen                  = true;
            string videoMode                   = "";
            bool   multiMonitorMode            = false;
            bool   verticalSync                = true;
            bool   allowChangeDisplayFrequency = true;
            string physicsSystemComponentName  = "";
            //bool physicsAllowHardwareAcceleration = false;
            string soundSystemComponentName = "";
            string language             = "Autodetect";
            bool   localizeEngine       = true;
            bool   localizeToolset      = true;
            string renderingDeviceName  = "";
            int    renderingDeviceIndex = 0;

            //load from Deployment.config
            if (VirtualFileSystem.Deployed)
            {
                if (!string.IsNullOrEmpty(VirtualFileSystem.DeploymentParameters.DefaultLanguage))
                {
                    language = VirtualFileSystem.DeploymentParameters.DefaultLanguage;
                }
            }

            //load from Engine.config
            {
                string    error;
                TextBlock block = TextBlockUtils.LoadFromRealFile(
                    VirtualFileSystem.GetRealPathByVirtual("user:Configs/Engine.config"),
                    out error);
                if (block != null)
                {
                    //Renderer
                    TextBlock rendererBlock = block.FindChild("Renderer");
                    if (rendererBlock != null)
                    {
                        renderingSystemComponentName = rendererBlock.GetAttribute("implementationComponent");

                        if (rendererBlock.IsAttributeExist("renderingDeviceName"))
                        {
                            renderingDeviceName = rendererBlock.GetAttribute("renderingDeviceName");
                        }
                        if (rendererBlock.IsAttributeExist("renderingDeviceIndex"))
                        {
                            renderingDeviceIndex = int.Parse(rendererBlock.GetAttribute("renderingDeviceIndex"));
                        }
                        if (rendererBlock.IsAttributeExist("allowShaders"))
                        {
                            allowShaders = bool.Parse(rendererBlock.GetAttribute("allowShaders"));
                        }
                        if (rendererBlock.IsAttributeExist("depthBufferAccess"))
                        {
                            depthBufferAccess = bool.Parse(rendererBlock.GetAttribute("depthBufferAccess"));
                        }
                        if (rendererBlock.IsAttributeExist("fullSceneAntialiasing"))
                        {
                            fullSceneAntialiasing = rendererBlock.GetAttribute("fullSceneAntialiasing");
                        }

                        if (rendererBlock.IsAttributeExist("filtering"))
                        {
                            try
                            {
                                filtering = (RendererWorld.FilteringModes)
                                            Enum.Parse(typeof(RendererWorld.FilteringModes),
                                                       rendererBlock.GetAttribute("filtering"));
                            }
                            catch { }
                        }

                        if (rendererBlock.IsAttributeExist("renderTechnique"))
                        {
                            renderTechnique = rendererBlock.GetAttribute("renderTechnique");
                        }

                        if (rendererBlock.IsAttributeExist("fullScreen"))
                        {
                            fullScreen = bool.Parse(rendererBlock.GetAttribute("fullScreen"));
                        }

                        if (rendererBlock.IsAttributeExist("videoMode"))
                        {
                            videoMode = rendererBlock.GetAttribute("videoMode");
                        }

                        if (rendererBlock.IsAttributeExist("multiMonitorMode"))
                        {
                            multiMonitorMode = bool.Parse(rendererBlock.GetAttribute("multiMonitorMode"));
                        }

                        if (rendererBlock.IsAttributeExist("verticalSync"))
                        {
                            verticalSync = bool.Parse(rendererBlock.GetAttribute("verticalSync"));
                        }

                        if (rendererBlock.IsAttributeExist("allowChangeDisplayFrequency"))
                        {
                            allowChangeDisplayFrequency = bool.Parse(
                                rendererBlock.GetAttribute("allowChangeDisplayFrequency"));
                        }
                    }

                    //Physics system
                    TextBlock physicsSystemBlock = block.FindChild("PhysicsSystem");
                    if (physicsSystemBlock != null)
                    {
                        physicsSystemComponentName = physicsSystemBlock.GetAttribute("implementationComponent");
                        //if( physicsSystemBlock.IsAttributeExist( "allowHardwareAcceleration" ) )
                        //{
                        //   physicsAllowHardwareAcceleration =
                        //      bool.Parse( physicsSystemBlock.GetAttribute( "allowHardwareAcceleration" ) );
                        //}
                    }

                    //Sound system
                    TextBlock soundSystemBlock = block.FindChild("SoundSystem");
                    if (soundSystemBlock != null)
                    {
                        soundSystemComponentName = soundSystemBlock.GetAttribute("implementationComponent");
                    }

                    //Localization
                    TextBlock localizationBlock = block.FindChild("Localization");
                    if (localizationBlock != null)
                    {
                        if (localizationBlock.IsAttributeExist("language"))
                        {
                            language = localizationBlock.GetAttribute("language");
                        }
                        if (localizationBlock.IsAttributeExist("localizeEngine"))
                        {
                            localizeEngine = bool.Parse(localizationBlock.GetAttribute("localizeEngine"));
                        }
                        if (localizationBlock.IsAttributeExist("localizeToolset"))
                        {
                            localizeToolset = bool.Parse(localizationBlock.GetAttribute("localizeToolset"));
                        }
                    }
                }
            }

            //init toolset language
            if (localizeToolset)
            {
                if (!string.IsNullOrEmpty(language))
                {
                    string language2 = language;
                    if (string.Compare(language2, "autodetect", true) == 0)
                    {
                        language2 = DetectLanguage();
                    }
                    string languageDirectory = Path.Combine(LanguageManager.LanguagesDirectory, language2);
                    string fileName          = Path.Combine(languageDirectory, "Configurator.language");
                    ToolsLocalization.Init(fileName);
                }
            }

            //fill render system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.RenderingSystem);

                if (string.IsNullOrEmpty(renderingSystemComponentName))
                {
                    //find component by default
                    foreach (EngineComponentManager.ComponentInfo component2 in components)
                    {
                        if (component2.IsEnabledByDefaultForThisPlatform())
                        {
                            renderingSystemComponentName = component2.Name;
                            break;
                        }
                    }
                }

                //rendering systems combo box
                foreach (EngineComponentManager.ComponentInfo component in components)
                {
                    string text = component.FullName;
                    if (component.IsEnabledByDefaultForThisPlatform())
                    {
                        text = string.Format(Translate("{0} (default)"), text);
                    }
                    int itemId = comboBoxRenderSystems.Items.Add(text);
                    if (renderingSystemComponentName == component.Name)
                    {
                        comboBoxRenderSystems.SelectedIndex = itemId;
                    }
                }
                if (comboBoxRenderSystems.Items.Count != 0 && comboBoxRenderSystems.SelectedIndex == -1)
                {
                    comboBoxRenderSystems.SelectedIndex = 0;
                }

                //rendering device
                {
                    if (comboBoxRenderingDevices.Items.Count > 1 && !string.IsNullOrEmpty(renderingDeviceName))
                    {
                        int deviceCountWithSelectedName = 0;

                        for (int n = 1; n < comboBoxRenderingDevices.Items.Count; n++)
                        {
                            string name = (string)comboBoxRenderingDevices.Items[n];
                            if (name == renderingDeviceName)
                            {
                                comboBoxRenderingDevices.SelectedIndex = n;
                                deviceCountWithSelectedName++;
                            }
                        }

                        if (deviceCountWithSelectedName > 1)
                        {
                            int comboBoxIndex = renderingDeviceIndex + 1;
                            if (comboBoxIndex < comboBoxRenderingDevices.Items.Count)
                            {
                                string name = (string)comboBoxRenderingDevices.Items[comboBoxIndex];
                                if (name == renderingDeviceName)
                                {
                                    comboBoxRenderingDevices.SelectedIndex = comboBoxIndex;
                                }
                            }
                        }
                    }

                    if (comboBoxRenderingDevices.SelectedIndex == -1 && comboBoxRenderingDevices.Items.Count != 0)
                    {
                        comboBoxRenderingDevices.SelectedIndex = 0;
                    }
                }

                //allowShaders
                checkBoxAllowShaders.Checked = allowShaders;

                //depthBufferAccess
                comboBoxDepthBufferAccess.Items.Add(Translate("No"));
                comboBoxDepthBufferAccess.Items.Add(Translate("Yes"));
                comboBoxDepthBufferAccess.SelectedIndex = depthBufferAccess ? 1 : 0;

                //fullSceneAntialiasing
                for (int n = 0; n < comboBoxAntialiasing.Items.Count; n++)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.Items[n];
                    if (item.Identifier == fullSceneAntialiasing)
                    {
                        comboBoxAntialiasing.SelectedIndex = n;
                    }
                }
                if (comboBoxAntialiasing.SelectedIndex == -1)
                {
                    comboBoxAntialiasing.SelectedIndex = 0;
                }

                //filtering
                {
                    Type enumType = typeof(RendererWorld.FilteringModes);
                    LocalizedEnumConverter enumConverter = new LocalizedEnumConverter(enumType);

                    RendererWorld.FilteringModes[] values =
                        (RendererWorld.FilteringModes[])Enum.GetValues(enumType);
                    for (int n = 0; n < values.Length; n++)
                    {
                        RendererWorld.FilteringModes value = values[n];
                        int index = comboBoxFiltering.Items.Add(enumConverter.ConvertToString(value));
                        if (filtering == value)
                        {
                            comboBoxFiltering.SelectedIndex = index;
                        }
                    }
                }

                //renderTechnique
                {
                    comboBoxRenderTechnique.Items.Add(new ComboBoxItem("RecommendedSetting", "Recommended setting"));
                    comboBoxRenderTechnique.Items.Add(new ComboBoxItem("Standard", "Low Dynamic Range (Standard)"));
                    comboBoxRenderTechnique.Items.Add(new ComboBoxItem("HDR", "64-bit High Dynamic Range (HDR)"));

                    for (int n = 0; n < comboBoxRenderTechnique.Items.Count; n++)
                    {
                        ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.Items[n];
                        if (item.Identifier == renderTechnique)
                        {
                            comboBoxRenderTechnique.SelectedIndex = n;
                        }
                    }
                    if (comboBoxRenderTechnique.SelectedIndex == -1)
                    {
                        comboBoxRenderTechnique.SelectedIndex = 0;
                    }
                }

                //video mode
                {
                    comboBoxVideoMode.Items.Add(Translate("Current screen resolution"));
                    comboBoxVideoMode.SelectedIndex = 0;

                    comboBoxVideoMode.Items.Add(Translate("Use all displays (multi-monitor mode)"));
                    if (multiMonitorMode)
                    {
                        comboBoxVideoMode.SelectedIndex = 1;
                    }

                    foreach (Vec2I mode in DisplaySettings.VideoModes)
                    {
                        if (mode.X < 640)
                        {
                            continue;
                        }
                        comboBoxVideoMode.Items.Add(string.Format("{0}x{1}", mode.X, mode.Y));
                        if (mode.ToString() == videoMode)
                        {
                            comboBoxVideoMode.SelectedIndex = comboBoxVideoMode.Items.Count - 1;
                        }
                    }

                    if (!string.IsNullOrEmpty(videoMode) && comboBoxVideoMode.SelectedIndex == 0)
                    {
                        try
                        {
                            Vec2I mode = Vec2I.Parse(videoMode);
                            comboBoxVideoMode.Items.Add(string.Format("{0}x{1}", mode.X, mode.Y));
                            comboBoxVideoMode.SelectedIndex = comboBoxVideoMode.Items.Count - 1;
                        }
                        catch { }
                    }
                }

                //full screen
                checkBoxFullScreen.Checked = fullScreen;

                //vertical sync
                checkBoxVerticalSync.Checked = verticalSync;
            }

            //fill physics system page
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.PhysicsSystem);

                if (string.IsNullOrEmpty(physicsSystemComponentName))
                {
                    //find component by default
                    foreach (EngineComponentManager.ComponentInfo component2 in components)
                    {
                        if (component2.IsEnabledByDefaultForThisPlatform())
                        {
                            physicsSystemComponentName = component2.Name;
                            break;
                        }
                    }
                }

                //update combo box
                foreach (EngineComponentManager.ComponentInfo component in components)
                {
                    string text = component.FullName;
                    if (component.IsEnabledByDefaultForThisPlatform())
                    {
                        text = string.Format(Translate("{0} (default)"), text);
                    }

                    int itemId = comboBoxPhysicsSystems.Items.Add(text);
                    if (physicsSystemComponentName == component.Name)
                    {
                        comboBoxPhysicsSystems.SelectedIndex = itemId;
                    }
                }
                if (comboBoxPhysicsSystems.SelectedIndex == -1)
                {
                    comboBoxPhysicsSystems.SelectedIndex = 0;
                }

                //if( checkBoxPhysicsAllowHardwareAcceleration.Enabled )
                //   checkBoxPhysicsAllowHardwareAcceleration.Checked = physicsAllowHardwareAcceleration;
            }

            //fill sound system page
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.SoundSystem);

                if (string.IsNullOrEmpty(soundSystemComponentName))
                {
                    //find component by default
                    foreach (EngineComponentManager.ComponentInfo component2 in components)
                    {
                        if (component2.IsEnabledByDefaultForThisPlatform())
                        {
                            soundSystemComponentName = component2.Name;
                            break;
                        }
                    }
                }

                //update combo box
                foreach (EngineComponentManager.ComponentInfo component in components)
                {
                    string text = component.FullName;
                    if (component.IsEnabledByDefaultForThisPlatform())
                    {
                        text = string.Format(Translate("{0} (default)"), text);
                    }

                    int itemId = comboBoxSoundSystems.Items.Add(text);
                    if (soundSystemComponentName == component.Name)
                    {
                        comboBoxSoundSystems.SelectedIndex = itemId;
                    }
                }
                if (comboBoxSoundSystems.SelectedIndex == -1)
                {
                    comboBoxSoundSystems.SelectedIndex = 0;
                }
            }

            //fill localization page
            {
                List <string> languages = new List <string>();
                {
                    languages.Add(Translate("Autodetect"));
                    string[] directories = VirtualDirectory.GetDirectories(LanguageManager.LanguagesDirectory,
                                                                           "*.*", SearchOption.TopDirectoryOnly);
                    foreach (string directory in directories)
                    {
                        languages.Add(Path.GetFileNameWithoutExtension(directory));
                    }
                }

                foreach (string lang in languages)
                {
                    int itemId = comboBoxLanguages.Items.Add(lang);
                    if (string.Compare(language, lang, true) == 0)
                    {
                        comboBoxLanguages.SelectedIndex = itemId;
                    }
                }

                if (comboBoxLanguages.SelectedIndex == -1)
                {
                    comboBoxLanguages.SelectedIndex = 0;
                }

                checkBoxLocalizeEngine.Checked  = localizeEngine;
                checkBoxLocalizeToolset.Checked = localizeToolset;
            }

            Translate();

            formLoaded = true;
        }
Esempio n. 5
0
        void ChangeToBetterDefaultSettings()
        {
            bool shadowTechniqueInitialized   = false;
            bool shadowTextureSizeInitialized = false;

            if (!string.IsNullOrEmpty(EngineApp.ConfigName))
            {
                string    error;
                TextBlock block = TextBlockUtils.LoadFromRealFile(
                    VirtualFileSystem.GetRealPathByVirtual(EngineApp.ConfigName), out error);
                if (block != null)
                {
                    TextBlock blockVideo = block.FindChild("Video");
                    if (blockVideo != null)
                    {
                        if (blockVideo.IsAttributeExist("shadowTechnique"))
                        {
                            shadowTechniqueInitialized = true;
                        }
                        if (blockVideo.IsAttributeExist("shadowDirectionalLightTextureSize"))
                        {
                            shadowTextureSizeInitialized = true;
                        }
                    }
                }
            }

            //shadowTechnique
            if (!shadowTechniqueInitialized)
            {
                if (RenderSystem.Instance.GPUIsGeForce())
                {
                    if (RenderSystem.Instance.GPUCodeName >= GPUCodeNames.GeForce_NV10 &&
                        RenderSystem.Instance.GPUCodeName <= GPUCodeNames.GeForce_NV40)
                    {
                        shadowTechnique = ShadowTechniques.ShadowmapLow;
                    }
                    if (RenderSystem.Instance.GPUCodeName == GPUCodeNames.GeForce_G70)
                    {
                        shadowTechnique = ShadowTechniques.ShadowmapMedium;
                    }
                }

                if (RenderSystem.Instance.GPUIsRadeon())
                {
                    if (RenderSystem.Instance.GPUCodeName >= GPUCodeNames.Radeon_R100 &&
                        RenderSystem.Instance.GPUCodeName <= GPUCodeNames.Radeon_R400)
                    {
                        shadowTechnique = ShadowTechniques.ShadowmapLow;
                    }
                    if (RenderSystem.Instance.GPUCodeName == GPUCodeNames.Radeon_R500)
                    {
                        shadowTechnique = ShadowTechniques.ShadowmapMedium;
                    }
                }

                if (!RenderSystem.Instance.HasShaderModel2())
                {
                    shadowTechnique = ShadowTechniques.None;
                }
            }

            //shadow texture size
            if (!shadowTextureSizeInitialized)
            {
                if (RenderSystem.Instance.GPUIsGeForce())
                {
                    if (RenderSystem.Instance.GPUCodeName >= GPUCodeNames.GeForce_NV10 &&
                        RenderSystem.Instance.GPUCodeName <= GPUCodeNames.GeForce_G70)
                    {
                        shadowDirectionalLightTextureSize = 1024;
                        shadowSpotLightTextureSize        = 1024;
                        shadowPointLightTextureSize       = 512;
                    }
                }
                else if (RenderSystem.Instance.GPUIsRadeon())
                {
                    if (RenderSystem.Instance.GPUCodeName >= GPUCodeNames.Radeon_R100 &&
                        RenderSystem.Instance.GPUCodeName <= GPUCodeNames.Radeon_R500)
                    {
                        shadowDirectionalLightTextureSize = 1024;
                        shadowSpotLightTextureSize        = 1024;
                        shadowPointLightTextureSize       = 512;
                    }
                }
                else
                {
                    shadowDirectionalLightTextureSize = 1024;
                    shadowSpotLightTextureSize        = 1024;
                    shadowPointLightTextureSize       = 512;
                }
            }
        }
        private void btnBuy_Click(Button sender)
        {
            //find hangar for what we are trying to spawn

            Hangar selectedHangar = null;

            if (currentList == MechDBUnits)
            {
                selectedHangar = mechHangar;
            }

            if (currentList == GDBUnits)
            {
                selectedHangar = groundUnitHangar;
            }

            if (currentList == ADBUnits)
            {
                selectedHangar = airUnitHangar;
            }

            if (currentList == JDBUnits)
            {
                selectedHangar = jetHangar;
            }

            string un = currentPriceList.Type.PriceLists[
                int.Parse(SelectedB.Controls["RelatedUnitID"].Text)].PricedUnit.Name;

            UnitType ut = (UnitType)EntityTypes.Instance.GetByName(un);

            TextBlock variant = null;

            if (variantList.SelectedIndex > 0)
            {
                string varName = string.Format("{0}\\Variants\\{1}\\{2}",
                                               VirtualFileSystem.UserDirectoryPath, ut.Name, variantList.SelectedItem.ToString());

                variant = TextBlockUtils.LoadFromRealFile(varName);
            }

            //parse TextBlock to int[] so it can be networked more efficiently

            AKunitType akt = ut as AKunitType;

            int[]  varData       = null;
            string varDataString = string.Empty;

            if (variant != null)
            {
                //calculate the elements needed for the compressed variant data
                {
                    int elementCount = 0;
                    foreach (TextBlock c in variant.Children)
                    {
                        elementCount += c.Children.Count;
                    }

                    elementCount *= 4;

                    varData = new int[elementCount];
                }

                int x = 0;
                for (int i = 0; i < akt.BodyParts.Count; i++)
                {
                    TextBlock bodyPartBlock = variant.FindChild(akt.BodyParts[i].GUIDesplayName);

                    if (bodyPartBlock != null)
                    {
                        int bodyPartIndex      = i;
                        int bodyPartBlockIndex = variant.Children.IndexOf(bodyPartBlock);

                        AKunitType.BodyPart bodyPart = akt.BodyParts[i];

                        for (int j = 0; j < bodyPart.Weapons.Count; j++)
                        {
                            TextBlock bodyPartWeaponBlock =
                                bodyPartBlock.FindChild(bodyPart.Weapons[j].MapObjectAlias);

                            if (bodyPartWeaponBlock != null)
                            {
                                int bodyPartWeaponIndex = j;

                                int alternateWeaponIndex = int.Parse(bodyPartWeaponBlock.Attributes[0].Value);
                                int fireGroup            = int.Parse(bodyPartWeaponBlock.Attributes[1].Value);
                                varData[x]     = bodyPartIndex;
                                varData[x + 1] = bodyPartWeaponIndex;
                                varData[x + 2] = alternateWeaponIndex;
                                varData[x + 3] = fireGroup;

                                if (varDataString != string.Empty)
                                {
                                    varDataString += ":";
                                }

                                varDataString += string.Format("{0}:{1}:{2}:{3}",
                                                               bodyPartIndex, bodyPartWeaponIndex, alternateWeaponIndex, fireGroup);
                                x += 4;
                            }
                        }
                    }
                }
            }

            if (EntitySystemWorld.Instance.IsClientOnly())
            {
                selectedHangar.Client_SendSpawnRequestToServer(ut.Name, varDataString);
            }
            else
            {
                selectedHangar.SpawnNewUnit(ut, varData);
            }

            SetShouldDetach();
        }