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

            return(TextBlockUtils.LoadFromRealFile(fileName, out error));
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
0
        private static void A()
        {
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(ToolsLocalization.EL);

            if (textBlock != null)
            {
                TextBlock textBlock2 = textBlock.FindChild("groups");
                if (textBlock2 != null)
                {
                    foreach (TextBlock current in textBlock2.Children)
                    {
                        if (!(current.Name != "group"))
                        {
                            string data = current.Data;
                            ToolsLocalization.GroupItem groupItem = new ToolsLocalization.GroupItem(data);
                            ToolsLocalization.EM.Add(data, groupItem);
                            foreach (TextBlock.Attribute current2 in current.Attributes)
                            {
                                groupItem.em.Add(current2.Name, current2.Value);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        internal static bool C(string p)
        {
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(p);

            if (textBlock == null)
            {
                return(false);
            }
            Entities.Instance.Internal_InitUINOffset();
            Map.Instance.virtualFileName = p;
            if (!Entities.Instance.Internal_LoadEntityTreeFromTextBlock(Map.Instance, textBlock, true, null))
            {
                MapSystemWorld.MapDestroy();
                return(false);
            }

            /*
             * if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor)
             * {
             *  Map.Instance.GetDataForEditor().ClearAll();
             * }
             * //*/

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads a world from file.
        /// </summary>
        /// <param name="worldSimulationType">The world similation type.</param>
        /// <param name="virtualFileName">The file name of virtual file system.</param>
        /// <returns><b>true</b> if the world has been loaded; otherwise, <b>false</b>.</returns>
        public static bool WorldLoad(WorldSimulationTypes worldSimulationType, string virtualFileName)
        {
            if (EntitySystemWorld.Instance == null)
            {
                Log.Fatal("MapSystemWorld: WorldLoad: EntitySystemWorld.Instance == null");
                return(false);
            }
            virtualFileName = PathUtils.NormalizeSlashes(virtualFileName);
            MapDestroy();
            EntitySystemWorld.Instance.WorldDestroy();
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(virtualFileName);

            if (textBlock == null)
            {
                return(false);
            }

            string    worldTypeName = textBlock.GetAttribute("type");
            WorldType worldType     = EntityTypes.Instance.GetByName(worldTypeName) as WorldType;

            if (worldType == null)
            {
                Log.Error("世界加载失败: 世界类型 \"{0}\" 未定义。", worldTypeName);
                return(false);
            }

            WorldLoad(textBlock);
            if (!EntitySystemWorld.Instance.WorldCreateWithoutPostCreate(worldSimulationType, worldType))
            {
                MapDestroy();
                EntitySystemWorld.Instance.WorldDestroy();
                return(false);
            }
            Entities.Instance.Internal_InitUINOffset();
            Map.WorldFileName = virtualFileName;
            if (!Entities.Instance.Internal_LoadEntityTreeFromTextBlock(World.Instance, textBlock, true, null))
            {
                MapDestroy();
                EntitySystemWorld.Instance.WorldDestroy();
                return(false);
            }

            /*
             * if (Map.Instance != null && EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor)
             * {
             *  Map.Instance.GetDataForEditor().ClearAll();
             * }
             * //*/
            Map.WorldFileName = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            EntitySystemWorld.Instance.ResetExecutedTime();
            return(true);
        }
Exemplo n.º 6
0
        private string GetMapLoopFromConfig()
        {
            //EngineApp.Instance.Config.Parameters.
            string    error;
            TextBlock block = TextBlockUtils.LoadFromVirtualFile("user:Configs/DedicatedServer.config", out error);

            if (block != null)
            {
                return(block.GetAttribute("MapLoop"));
            }
            return("");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Loads a map from file.
        /// </summary>
        /// <param name="virtualFileName">The file name of virtual file system.</param>
        /// <returns><b>true</b> if the map has been loaded; otherwise, <b>false</b>.</returns>
        public static bool MapLoad(string virtualFileName)
        {
            virtualFileName = PathUtils.NormalizeSlashes(virtualFileName);
            LongOperationNotifier.Notify("加载地图: {0}", virtualFileName);

            if (World.Instance == null)
            {
                Log.Fatal("MapSystemWorld: MapLoad: World.Instance == null.");
                return(false);
            }

            MapDestroy();
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(virtualFileName);

            if (textBlock == null)
            {
                return(false);
            }

            string  mapTypeName = textBlock.GetAttribute("type");
            MapType mapType     = EntityTypes.Instance.GetByName(mapTypeName) as MapType;

            if (mapType == null)
            {
                Log.Error("地图加载错误: 地图类型 \"{0}\" 未定义。", mapTypeName);
                return(false);
            }

            Entities.Instance.Internal_InitUINOffset();
            uint uin = uint.Parse(textBlock.GetAttribute("uin"));
            Map  map = (Map)Entities.Instance._CreateInternal(mapType, World.Instance, uin, 0u);

            map.virtualFileName = virtualFileName;
            if (!Entities.Instance.Internal_LoadEntityTreeFromTextBlock(map, textBlock, true, null))
            {
                MapDestroy();
                return(false);
            }
            //TODO

            /*
             * if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor)
             * {
             *  map.GetDataForEditor().ClearAll();
             * }
             * //*/

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            EntitySystemWorld.Instance.ResetExecutedTime();
            return(true);
        }
Exemplo n.º 8
0
        private EntityType loadEntityTypeFromFile(string p)
        {
            LongOperationNotifier.Notify("加载type文件: {0}", p);
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(p);

            if (textBlock == null)
            {
                return(null);
            }

            EntityType result = loadEntityType(textBlock, p, p);    // loadEntityTypeFromFile

            return(result);
        }
Exemplo n.º 9
0
        public override void Create(ResourceType resourceType, string fileName)
        {
            base.Create(resourceType, fileName);
            this.textBlock = TextBlockUtils.LoadFromVirtualFile(base.FileName);
            if (this.textBlock != null)
            {
                base.AllowEditMode = true;
            }

            MainForm.Instance.PropertiesForm.SelectObjects(new object[]
            {
                this
            });
        }
Exemplo n.º 10
0
        protected override bool OnOutsideAddResource(string path)
        {
            string data;

            try
            {
                string    message;
                TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(path, out message);
                if (textBlock == null)
                {
                    throw new Exception(message);
                }
                if (textBlock.Children.Count == 0)
                {
                    throw new Exception("Invalid format");
                }
                TextBlock textBlock2 = textBlock.Children[0];
                if (string.Compare(textBlock2.Name, "type", true) != 0)
                {
                    throw new Exception("Invalid format");
                }
                data = textBlock2.Data;
            }
            catch (Exception ex)
            {
                Log.Warning(this.A("Unable to load entity type \"{0}\" ({1})."), path, ex.Message);
                return(false);
            }
            if (data != "")
            {
                int    num = 1;
                string text;
                while (true)
                {
                    text = data;
                    if (num != 1)
                    {
                        text += num.ToString();
                    }
                    if (EntityTypes.Instance.GetByName(text) == null)
                    {
                        break;
                    }
                    num++;
                }
                this.A(path, path, text);
            }
            return(base.OnOutsideAddResource(path));
        }
Exemplo n.º 11
0
        public void listBox_SelectedIndexChanged(object sender)
        {
            Texture texture     = null;
            string  description = "";

            ListBox listBox = (ListBox)Owner.MainControl.Controls["List"];

            if (listBox.SelectedIndex != -1)
            {
                string mapName      = (string)listBox.SelectedItem;
                string mapDirectory = System.IO.Path.GetDirectoryName(mapName);

                //get texture
                string   textureName     = mapDirectory + "\\Description\\Preview";
                string   textureFileName = null;
                string[] extensions      = new string[] { "dds", "tga", "png", "jpg" };
                foreach (string extension in extensions)
                {
                    string fileName = textureName + "." + extension;
                    if (VirtualFile.Exists(fileName))
                    {
                        textureFileName = fileName;
                        break;
                    }
                }
                if (textureFileName != null)
                {
                    texture = TextureManager.Instance.Load(textureFileName);
                }

                //get description text
                string descriptionFileName = mapDirectory + "\\Description\\Description.config";
                if (VirtualFile.Exists(descriptionFileName))
                {
                    string    error;
                    TextBlock block = TextBlockUtils.LoadFromVirtualFile(descriptionFileName, out error);
                    if (block != null)
                    {
                        description = block.GetAttribute("description");
                    }
                }

                ActivateTeleporter(mapName);
            }

            Owner.MainControl.Controls["Preview"].BackTexture = texture;
            Owner.MainControl.Controls["Description"].Text    = description;
        }
Exemplo n.º 12
0
        private void A(string text, string virtualPath, string data)
        {
            TextBlock textBlock;

            try
            {
                string message;
                textBlock = TextBlockUtils.LoadFromVirtualFile(text, out message);
                if (textBlock == null)
                {
                    throw new Exception(message);
                }
                if (textBlock.Children.Count == 0)
                {
                    throw new Exception("Invalid format");
                }
                TextBlock textBlock2 = textBlock.Children[0];
                if (string.Compare(textBlock2.Name, "type", true) != 0)
                {
                    throw new Exception("Invalid format");
                }
                textBlock2.Data = data;
            }
            catch (Exception ex)
            {
                Log.Warning(this.A("Unable to load entity type \"{0}\" ({1})."), text, ex.Message);
                return;
            }
            string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(virtualPath);

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(realPathByVirtual))
                {
                    streamWriter.Write(textBlock.DumpToString());
                }
            }
            catch (Exception ex2)
            {
                Log.Warning(this.A("Unable to save file \"{0}\" ({1})."), realPathByVirtual, ex2.Message);
            }
        }
Exemplo n.º 13
0
        public EntityType LoadType(string p)
        {
            LongOperationNotifier.Notify("加载EntityType: {0}", p);
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(p);

            if (textBlock == null || textBlock.Children.Count != 1)
            {
                return(null);
            }

            TextBlock tc = textBlock.Children[0];

            if (tc.Name != "type")
            {
                return(null);
            }

            EntityType entityType = loadEntityType(textBlock, p, p);    // LoadType

            return(entityType);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        protected override bool OnInitLibrary(bool allowHardwareAcceleration, bool editor)
        {
            instance = this;

            NativeLibraryManager.PreLoadLibrary("ode");

            //int maxIterationCount = 20;
            //int hashSpaceMinLevel = 2;// 2^2 = 4 minimum cell size
            //int hashSpaceMaxLevel = 8;// 2^8 = 256 maximum cell size

            if (VirtualFile.Exists("Base/Constants/PhysicsSystem.config"))
            {
                TextBlock block = TextBlockUtils.LoadFromVirtualFile("Base/Constants/PhysicsSystem.config");
                if (block != null)
                {
                    TextBlock odeBlock = block.FindChild("odeSpecific");
                    if (odeBlock != null)
                    {
                        if (odeBlock.IsAttributeExist("maxIterationCount"))
                        {
                            defaultMaxIterationCount = int.Parse(odeBlock.GetAttribute("maxIterationCount"));
                        }
                        if (odeBlock.IsAttributeExist("hashSpaceMinLevel"))
                        {
                            hashSpaceMinLevel = int.Parse(odeBlock.GetAttribute("hashSpaceMinLevel"));
                        }
                        if (odeBlock.IsAttributeExist("hashSpaceMaxLevel"))
                        {
                            hashSpaceMaxLevel = int.Parse(odeBlock.GetAttribute("hashSpaceMaxLevel"));
                        }
                    }
                }
            }

            Ode.dInitODE2(0);

            return(true);
        }
Exemplo n.º 16
0
        private void initConfig()
        {
            string p = string.Format("Base/Constants/{0}.config", Program.ExecutableName);

            Log.Info(">> 配置文件: {0}", p);

            string defaultMapTypeName = typeof(DefaultMap).Name;

            if (VirtualFile.Exists(p))
            {
                TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(p);
                if (textBlock != null)
                {
                    this.MapTypeName = textBlock.GetAttribute("mapTypeForNewMaps", defaultMapTypeName);
                }
            }

            if (string.IsNullOrEmpty(this.MapTypeName))
            {
                this.MapTypeName = defaultMapTypeName;
            }

            Log.Info(">> 缺省地图类型: {0}", this.MapTypeName);
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
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;
                }
            }
        }
Exemplo n.º 19
0
        //static NxAssertResponse ReportAssertViolation( IntPtr pMessage, IntPtr pFile, int line )
        //{
        //   string message = Wrapper.GetOutString( pMessage );
        //   string file = Wrapper.GetOutString( pFile );

        //   if( file == null )
        //      file = "NULL";
        //   string text = string.Format( "PhysXPhysicsSystem: {0} ({1}:{2})", message, file, line );

        //   Log.Fatal( text );

        //   return NxAssertResponse.NX_AR_BREAKPOINT;
        //}

        protected override bool OnInitLibrary(bool allowHardwareAcceleration, bool editor)
        {
            instance = this;

            NativeLibraryManager.PreLoadLibrary("PhysXNativeWrapper");

            //change current directory for loading PhysX dlls from specified NativeDlls directory.
            string saveCurrentDirectory = null;

            if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
            {
                saveCurrentDirectory = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(NativeLibraryManager.GetNativeLibrariesDirectory());
            }

            try
            {
                preventLogErrors = true;

                reportErrorDelegate = ReportError;
                logDelegate         = LogMessage;
                IntPtr errorStringPtr;
                if (!PhysXNativeWorld.Init(reportErrorDelegate, out errorStringPtr, logDelegate, skinWidth))
                {
                    string errorString = Wrapper.GetOutString(errorStringPtr);
                    if (string.IsNullOrEmpty(errorString))
                    {
                        errorString = "Unknown error.";
                    }
                    Log.Fatal("PhysX: Initialization error: " + errorString);
                    return(false);
                }

                preventLogErrors = false;
            }
            finally
            {
                //restore current directory
                if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
                {
                    Directory.SetCurrentDirectory(saveCurrentDirectory);
                }
            }

            //configs
            if (VirtualFile.Exists("Base/Constants/PhysicsSystem.config"))
            {
                TextBlock block = TextBlockUtils.LoadFromVirtualFile("Base/Constants/PhysicsSystem.config");
                if (block != null)
                {
                    TextBlock physXBlock = block.FindChild("physXSpecific");
                    if (physXBlock != null)
                    {
                        if (physXBlock.IsAttributeExist("supportHeightFields"))
                        {
                            supportHeightFields = bool.Parse(physXBlock.GetAttribute("supportHeightFields"));
                        }

                        if (physXBlock.IsAttributeExist("supportVehicles"))
                        {
                            supportVehicles = bool.Parse(physXBlock.GetAttribute("supportVehicles"));
                        }

                        if (physXBlock.IsAttributeExist("writeCacheForCookedTriangleMeshes"))
                        {
                            writeCacheForCookedTriangleMeshes = bool.Parse(
                                physXBlock.GetAttribute("writeCacheForCookedTriangleMeshes"));
                        }

                        if (physXBlock.IsAttributeExist("mainSceneMaxThreads"))
                        {
                            mainSceneMaxThreads = int.Parse(physXBlock.GetAttribute("mainSceneMaxThreads"));
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 20
0
        void UpdateMapPreviewImageAndDescription()
        {
            //find selected map
            string mapName = null;

            if (listBoxRecentlyLoaded != null && listBoxRecentlyLoaded.SelectedIndex > 0)
            {
                mapName = (string)listBoxRecentlyLoaded.SelectedItem;
            }
            else
            {
                if (listBoxMaps != null && listBoxMaps.SelectedIndex != -1)
                {
                    string mapName2 = (string)listBoxMaps.SelectedItem;
                    if (mapName2 != exampleOfProceduralMapCreationText)
                    {
                        mapName = mapName2;
                    }
                }
            }

            //get texture and description
            Texture texture     = null;
            string  description = "";

            if (!string.IsNullOrEmpty(mapName))
            {
                string mapDirectory = Path.GetDirectoryName(mapName);

                //get texture
                string   textureName     = mapDirectory + "\\Description\\Preview";
                string   textureFileName = null;
                string[] extensions      = new string[] { "jpg", "png", "tga" };
                foreach (string extension in extensions)
                {
                    string fileName = textureName + "." + extension;
                    if (VirtualFile.Exists(fileName))
                    {
                        textureFileName = fileName;
                        break;
                    }
                }
                if (textureFileName != null)
                {
                    texture = TextureManager.Instance.Load(textureFileName);
                }

                //get description text
                string descriptionFileName = mapDirectory + "\\Description\\Description.config";
                if (VirtualFile.Exists(descriptionFileName))
                {
                    string    error;
                    TextBlock block = TextBlockUtils.LoadFromVirtualFile(descriptionFileName, out error);
                    if (block != null)
                    {
                        description = block.GetAttribute("description");
                    }
                }
            }

            //update controls
            window.Controls["Preview"].BackTexture = texture;
            window.Controls["Description"].Text    = description;
        }
Exemplo n.º 21
0
        private bool _Startup()
        {
            #region 缺省
            Entity.tickDelta = 20;
            #endregion

            TextBlock textBlock = null;
            if (VirtualFile.Exists("Base/Constants/EntitySystem.config"))
            {
                textBlock = TextBlockUtils.LoadFromVirtualFile("Base/Constants/EntitySystem.config");

                if (textBlock != null)
                {
                }
            }

            if (JxEngineApp.Instance != null)
            {
                Entity.tickDelta = JxEngineApp.Instance.LoopInterval;
            }

            CreateEntityClassAssembly(typeof(EntitySystemWorld).Assembly);
            CreateEntityClassAssembly(Assembly.GetExecutingAssembly());

            /*
             *          Assembly item = AssemblyUtils.LoadAssemblyByRealFileName("MapSystem.dll", false);
             *          entityClassAssemblies.Add(item);
             * //*/

            ComponentManager.ComponentInfo[] componentsByType = ComponentManager.Instance.GetComponentsByType(ComponentManager.ComponentTypeFlags.EntityClasses, true);

            for (int i = 0; i < componentsByType.Length; i++)
            {
                ComponentManager.ComponentInfo            componentInfo = componentsByType[i];
                ComponentManager.ComponentInfo.PathInfo[] allEntryPointsForThisPlatform = componentInfo.GetAllEntryPointsForThisPlatform();

                LongOperationNotifier.Notify("初始化组件({0}/{1}): {2}, 入口数: {3}",
                                             i + 1, componentsByType.Length, componentInfo.FullName, allEntryPointsForThisPlatform.Length);
                for (int j = 0; j < allEntryPointsForThisPlatform.Length; j++)
                {
                    ComponentManager.ComponentInfo.PathInfo pathInfo = allEntryPointsForThisPlatform[j];
                    Assembly assembly = AssemblyUtils.LoadAssemblyByRealFileName(pathInfo.Path, false);
                    CreateEntityClassAssembly(assembly);
                }
            }
            if (textBlock != null)
            {
                TextBlock logicSystemBlock = textBlock.FindChild("logicSystem");
                if (logicSystemBlock != null)
                {
                    TextBlock logicSystemClassAssembliesBlock = logicSystemBlock.FindChild("systemClassesAssemblies");
                    if (logicSystemClassAssembliesBlock != null)
                    {
                        foreach (TextBlock current in logicSystemClassAssembliesBlock.Children)
                        {
                            string assemblyFileName = current.GetAttribute("file");
                            logicSystemSystemClassesAssemblies.Add(assemblyFileName);
                        }
                    }
                }
            }
            LogicSystemClasses.Init();
            if (!EntityTypes.Init())
            {
                return(false);
            }

            if (textBlock != null)
            {
                string defaultWorldType = textBlock.GetAttribute("defaultWorldType");
                if (!string.IsNullOrEmpty(defaultWorldType))
                {
                    this.defaultWorldType = EntityTypes.Instance.GetByName(defaultWorldType) as WorldType;
                    if (this.defaultWorldType == null)
                    {
                        this.defaultWorldType = EntityTypes.Instance.GetByName(typeof(DefaultWorld).Name) as WorldType;
                    }
                }

                if (this.defaultWorldType == null)
                {
                    Log.Fatal("EntitySystemWorld: Init: World type \"{0}\" is not defined or it is not a WorldType (Base\\Constants\\EntitySystem.config: \"defaultWorldType\" attribute).", defaultWorldType);
                    return(false);
                }
            }

            Log.Info(">> 默认WorldType: {0}", defaultWorldType);
            return(true);
        }
Exemplo n.º 22
0
        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();
        }
Exemplo n.º 23
0
        void InitializeHDRCompositor()
        {
            bool editor = EngineApp.Instance.IsResourceEditor || EngineApp.Instance.IsMapEditor;

            //Add HDR compositor
            HDRCompositorInstance instance = (HDRCompositorInstance)
                                             RendererWorld.Instance.DefaultViewport.AddCompositor("HDR", 0);

            if (instance == null)
            {
                return;
            }

            //Enable HDR compositor
            instance.Enabled = true;

            //Load default settings
            TextBlock fileBlock = TextBlockUtils.LoadFromVirtualFile("Definitions/Renderer.config");

            if (fileBlock != null)
            {
                TextBlock hdrBlock = fileBlock.FindChild("hdr");
                if (hdrBlock != null)
                {
                    if (!editor)                     //No adaptation in the editors
                    {
                        if (hdrBlock.IsAttributeExist("adaptation"))
                        {
                            HDRCompositorInstance.Adaptation = bool.Parse(hdrBlock.GetAttribute("adaptation"));
                        }

                        if (hdrBlock.IsAttributeExist("adaptationVelocity"))
                        {
                            HDRCompositorInstance.AdaptationVelocity =
                                float.Parse(hdrBlock.GetAttribute("adaptationVelocity"));
                        }

                        if (hdrBlock.IsAttributeExist("adaptationMiddleBrightness"))
                        {
                            HDRCompositorInstance.AdaptationMiddleBrightness =
                                float.Parse(hdrBlock.GetAttribute("adaptationMiddleBrightness"));
                        }

                        if (hdrBlock.IsAttributeExist("adaptationMinimum"))
                        {
                            HDRCompositorInstance.AdaptationMinimum =
                                float.Parse(hdrBlock.GetAttribute("adaptationMinimum"));
                        }

                        if (hdrBlock.IsAttributeExist("adaptationMaximum"))
                        {
                            HDRCompositorInstance.AdaptationMaximum =
                                float.Parse(hdrBlock.GetAttribute("adaptationMaximum"));
                        }
                    }

                    if (hdrBlock.IsAttributeExist("bloomBrightThreshold"))
                    {
                        HDRCompositorInstance.BloomBrightThreshold =
                            float.Parse(hdrBlock.GetAttribute("bloomBrightThreshold"));
                    }

                    if (hdrBlock.IsAttributeExist("bloomScale"))
                    {
                        HDRCompositorInstance.BloomScale =
                            float.Parse(hdrBlock.GetAttribute("bloomScale"));
                    }
                }
            }
        }