Exemple #1
0
        protected override void AddPrefabItems(MyTreeViewItem parentItem, MyMwcObjectBuilder_Prefab_AppearanceEnum appearanceTextureEnum, BuildTypesEnum buildType, CategoryTypesEnum categoryType)
        {
            MyMwcLog.WriteLine("GAME AddPrefabItems - START");

            Vector2 itemSize = MyGuiConstants.CHECKBOX_SIZE * 3;

            foreach (MyMwcObjectBuilderTypeEnum enumValue in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
            {
                foreach (int prefabId in MyMwcObjectBuilder_Base.GetObjectBuilderIDs(enumValue))
                {
                    MyPrefabConfiguration config             = MyPrefabConstants.GetPrefabConfiguration(enumValue, prefabId);
                    MyGuiPrefabHelper     prefabModuleHelper = MyGuiObjectBuilderHelpers.GetGuiHelper(enumValue, prefabId) as MyGuiPrefabHelper;

                    if (config == null)
                    {
                        continue;
                    }

                    if (config.FactionSpecific.HasValue && config.FactionSpecific.Value != appearanceTextureEnum)
                    {
                        continue;
                    }

                    if (config.BuildType == buildType && config.CategoryType == categoryType && config.EnabledInEditor)
                    {
                        MyMwcObjectBuilder_PrefabBase prefabObjectBuilder   = MyPrefabFactory.GetInstance().CreatePrefabObjectBuilder(enumValue, prefabId, appearanceTextureEnum);
                        MyBuildingSpecification       buildingSpecification = MyBuildingSpecifications.GetBuildingSpecification(prefabObjectBuilder);
                        MyTexture2D previewTexture = MyGuiManager.GetPrefabPreviewTexture(enumValue, prefabId, appearanceTextureEnum);
                        AddTreeViewItem(parentItem, prefabModuleHelper.Description, previewTexture, itemSize, MyGuiManager.GetBlankTexture(), MyGuiManager.GetBlankTexture(), MyGuiConstants.CHECKBOX_SIZE, prefabObjectBuilder, buildingSpecification);
                    }
                }
            }

            MyMwcLog.WriteLine("GAME AddPrefabItems - END");
        }
Exemple #2
0
        private void OnGenerateListOfAssets(MyGuiControlButton sender)
        {
            string trimPath = @"Models2\";
            foreach (MyMwcObjectBuilderTypeEnum enumValue in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
            {
                foreach (int prefabId in MyMwcObjectBuilder_Base.GetObjectBuilderIDs(enumValue))
                {
                    MyGuiPrefabHelper prefabModuleHelper = MyGuiObjectBuilderHelpers.GetGuiHelper(enumValue, prefabId) as MyGuiPrefabHelper;
                    MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(enumValue, prefabId);
                    string assetName = MyModels.GetModelAssetName(config.ModelLod0Enum);
                    int trimIndex = assetName.IndexOf(trimPath);
                    if (trimIndex >= 0)
                    {
                        assetName = assetName.Substring(trimIndex + trimPath.Length);
                    }

                    MyMwcLog.WriteLine(string.Format("{0};{1}", prefabModuleHelper.Description, assetName));
                }
            }

            foreach (MyMwcObjectBuilder_SmallShip_TypesEnum enumValue in MyGuiSmallShipHelpers.MyMwcObjectBuilder_SmallShip_TypesEnumValues)
            {
                MyGuiSmallShipHelperSmallShip smallShipHelper = MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip, (int)enumValue) as MyGuiSmallShipHelperSmallShip;
                var properties = MyShipTypeConstants.GetShipTypeProperties(enumValue);
                string assetName = MyModels.GetModelAssetName(properties.Visual.ModelLod0Enum);
                int trimIndex = assetName.IndexOf(trimPath);
                if (trimIndex >= 0)
                {
                    assetName = assetName.Substring(trimIndex + trimPath.Length);
                }

                MyMwcLog.WriteLine(string.Format("{0};{1}", smallShipHelper.Description, assetName));
            }
        }
Exemple #3
0
        private void ShowPrefabEntitiesChange(MyGuiControlCheckbox sender)
        {
            if (sender.Checked)
            {
                Vector3 forward = MySession.PlayerShip.GetWorldRotation().Forward;
                Vector3 currentPosition = MySession.PlayerShip.GetPosition() + forward * 20;                

                foreach (MyMwcObjectBuilderTypeEnum prefabModuleEnum in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
                {
                    foreach (int prefabId in MyMwcObjectBuilder_Base.GetObjectBuilderIDs(prefabModuleEnum))
                    {                                                
                        MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(prefabModuleEnum, prefabId);

                        MyEntity debugDebris = addDebris(new StringBuilder(prefabModuleEnum + "_" + prefabId), config.ModelLod0Enum, config.ModelLod1Enum, ref currentPosition, forward);
                        m_debugPrefabEntities.Add(debugDebris);
                    }                    
                }

                
            }
            else
            {
                foreach (MyEntity entity in m_debugPrefabEntities)
                {
                    entity.MarkForClose();
                }
                m_debugPrefabEntities.Clear();
            }
            
        }
        /// <summary>
        /// CreatePrefabObjectBuilder
        /// </summary>
        /// <param name="prefabCategory"></param>
        /// <returns></returns>
        public MyMwcObjectBuilder_PrefabBase CreatePrefabObjectBuilder(MyMwcObjectBuilderTypeEnum prefabType, int prefabId, MyMwcObjectBuilder_Prefab_AppearanceEnum textureEnum)
        {
            MyGameplayProperties  gameplayProperties = MyGameplayConstants.GetGameplayProperties(prefabType, prefabId, MyMwcObjectBuilder_FactionEnum.Euroamerican);
            MyPrefabConfiguration prefabConfig       = MyPrefabConstants.GetPrefabConfiguration(prefabType, prefabId);
            MyMwcVector3Short     pos = new MyMwcVector3Short(0, 0, 0);

            MyMwcObjectBuilder_PrefabBase objBuilder = MyMwcObjectBuilder_Base.CreateNewObject(prefabType, prefabId) as MyMwcObjectBuilder_PrefabBase;

            objBuilder.PositionInContainer = pos;
            objBuilder.AnglesInContainer   = Vector3.Zero;
            objBuilder.PrefabHealthRatio   = MyGameplayConstants.HEALTH_RATIO_MAX;
            objBuilder.PrefabMaxHealth     = null;
            objBuilder.FactionAppearance   = textureEnum;
            objBuilder.IsDestructible      = gameplayProperties.IsDestructible;
            if (prefabConfig.DisplayHud)
            {
                objBuilder.PersistentFlags |= MyPersistentEntityFlags.DisplayOnHud;
            }

            return(objBuilder);
        }
        /// <summary>
        /// Creates new foundation factory from player's inventory. When player has no foundation factory in inventory, then returns result false.
        /// </summary>
        /// <param name="result">Result of foundation factory creation</param>
        /// <returns>Instance of new foundation factory</returns>
        public static MyPrefabFoundationFactory TryCreateFoundationFactory(MyPlayer player, out bool result)
        {
            MyPrefabFoundationFactory foundationFactory     = null;
            MyInventoryItem           foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT);

            if (foundationFactoryItem == null)
            {
                foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.FoundationFactory, null);
            }
            if (foundationFactoryItem == null)
            {
                result = false;
            }
            else
            {
                MyMwcObjectBuilder_PrefabFoundationFactory foundationFactoryBuilder =
                    MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT) as MyMwcObjectBuilder_PrefabFoundationFactory;
                MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                    null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List <MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(),
                    player.Faction, new MyMwcObjectBuilder_Inventory(new List <MyMwcObjectBuilder_InventoryItem>(), 1000));

                Matrix ffWorld = Matrix.Identity;
                ffWorld.Translation = player.Ship.WorldMatrix.Translation + player.Ship.WorldMatrix.Forward * 20;

                MyPrefabContainer prefabContainer = new MyPrefabContainer();
                prefabContainer.Init(null, prefabContainerBuilder, ffWorld);
                MyEntities.Add(prefabContainer);

                MyPrefabConfiguration ffConfiguration = MyPrefabConstants.GetPrefabConfiguration(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT);

                foundationFactory = new MyPrefabFoundationFactory(prefabContainer);
                foundationFactory.Init(null, new Vector3(0f, 0f, 0f), Matrix.Identity, foundationFactoryBuilder, ffConfiguration);
                prefabContainer.AddPrefab(foundationFactory);

                player.Ship.Inventory.RemoveInventoryItemAmount(ref foundationFactoryItem, 1f);

                result = true;
            }
            return(foundationFactory);
        }
        private void CreateDDSFiles(int sizeInPixels, DirectoryInfo directoryInfo)
        {
            int index = 1;

            foreach (MyMwcObjectBuilder_Prefab_TypesEnum enumValue in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
            {
                Debug.WriteLine(string.Format("Exporting Prefab Preview {0}/{1} ..", index++,
                                              MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues.Length));

                MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(enumValue);
                string lod0Name = GetPreviewFileName(config, enumValue);

                var    result   = RenderPreview(enumValue, config, sizeInPixels, sizeInPixels);
                string fileName = Path.Combine(directoryInfo.FullName, string.Format("{0}.dds", lod0Name));
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                MyDDSFile.DDSToFile(fileName, true, result, false);
            }
        }
Exemple #7
0
        private void GeneratePrefabPreviews(int sizeInPixels, DirectoryInfo directoryInfo)
        {
            var directoryPrefabs = Directory.CreateDirectory(Path.Combine(directoryInfo.FullName, "Prefabs"));

            //foreach (MyMwcObjectBuilderTypeEnum enumValue in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
            var enumValue = MyMwcObjectBuilderTypeEnum.Prefab;
            {
                int index = 0;
                //var prefabIds = MyMwcObjectBuilder_Base.GetObjectBuilderIDs(enumValue);
                var prefabIds = new[] { 534 };

                //if (enumValue == MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory) continue;
                // scanners has own preview texture
                //if (enumValue == MyMwcObjectBuilderTypeEnum.PrefabScanner) continue;

                foreach (int prefabId in prefabIds)
                {
                    if (prefabId == (ushort)MyMwcObjectBuilder_Prefab_TypesEnum.SimpleObject)
                    {
                        continue;
                    }

                    MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(enumValue, prefabId);

                    if (config == null)
                    {
                        continue;
                    }

                    string assetName = GetPreviewFileName(config, prefabId);

                    foreach (var faction in MyGuiPrefabHelpers.MyMwcFactionTextureEnumValues)
                    //var faction = MyMwcObjectBuilder_Prefab_AppearanceEnum.None;
                    {
                        var appearance = (MyMwcObjectBuilder_Prefab_AppearanceEnum)faction;

                        if (config.FactionSpecific.HasValue && config.FactionSpecific.Value != appearance)
                        {
                            continue;
                        }

                        var prefabTypeName = MyGuiObjectBuilderHelpers.GetGuiHelper(enumValue, prefabId).Description;
                        Debug.WriteLine(string.Format("Exporting prefab preview for {0}: {1}/{2} ..", prefabTypeName,
                                                      1 + (ushort)faction + 8 * index, 8 * prefabIds.Length));

                        var result = RenderPrefabPreview(prefabId, config, appearance,
                                                         sizeInPixels, sizeInPixels, 1.5f);

                        string fileName = Path.Combine(directoryPrefabs.FullName,
                                                       "v" + String.Format("{0:00}", (ushort)faction + 1),
                                                       string.Format("{0}.dds", assetName));

                        if (File.Exists(fileName))
                        {
                            File.Delete(fileName);
                        }

                        //TODO
                        //MyDDSFile.DDSToFile(fileName, true, result, false);
                    }

                    index++;
                }
            }
        }
        public MyMinerGame(ServiceContainer services)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame()::constructor");
            MyMwcLog.WriteLine("MyMinerGame.Constructor() - START");
            MyMwcLog.IncreaseIndent();

            Services = services;

            // we want check objectbuilders, prefab's configurations, gameplay constants and building specifications
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Checks");
            MyMwcObjectBuilder_Base.Check();
            MyPrefabConstants.Check();
            MyGameplayConstants.Check();
            MyBuildingSpecifications.Check();
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Preallocate");

            Preallocate();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("IsAdmin");
            WindowsIdentity  windowsIdentity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
            bool             IsAdmin          = windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);

            MyMwcLog.WriteLine("IsAdmin " + IsAdmin.ToString());
            MyMwcLog.WriteLine("Game dir: " + GameDir);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyCustomGraphicsDeviceManagerDX");
#if !DEBUG
            try
            {
#endif

            this.Exiting      += MyMinerGame_Exiting;
            this.Activated    += MyMinerGame_OnActivated;
            this.Deactivated  += MyMinerGame_OnDeactivated;
            this.m_InvokeQueue = new ConcurrentQueue <Tuple <ManualResetEvent, Action> >();
            this.m_MainThread  = Thread.CurrentThread;

            GraphicsDeviceManager = new MyCustomGraphicsDeviceManagerDX(this);

            m_isGraphicsSupported = GraphicsDeviceManager.ChangeProfileSupport();
            m_isGraphicsSupported = true;

            if (m_isGraphicsSupported)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.HookEventHandlers");

                MyVideoModeManager.HookEventHandlers();

                //Content = new MyCustomContentManager(Services, ContentDir);
                //  Content = new SharpDX.Toolkit.Content.ContentManager(Services);

                RootDirectory      = Path.Combine(GameDir, "Content");
                RootDirectoryDebug = Path.GetFullPath(System.IO.Path.Combine(GameDir, "..\\..\\..\\Content"));

                RootDirectoryEffects = RootDirectory;

                Static = this;

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitNumberOfCores");
                InitNumberOfCores();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogApplicationInformation");


                MyVideoModeManager.LogApplicationInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogInformation");

                MyVideoModeManager.LogInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogEnvironmentInformation");

                MyVideoModeManager.LogEnvironmentInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyPlugins.LoadContent");

                MyPlugins.LoadContent();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyConfig.Load");

                MyConfig.Load();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyMath.Init");

                MyMath.Init();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyTextsWrapper.Init");

                MyTextsWrapper.Init();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyDialoguesWrapper.Init");

                MyDialoguesWrapper.Init();

                //  If I don't set TargetElapsedTime, default value will be used, which is 60 times per second, and it will be more precise than if I calculate
                //  it like below - SO I MUST BE DOING THE WRONG CALCULATION !!!
                //  We use fixed timestep. Update() is called at this precise timesteps. If Update or Draw takes more time, Update will be called more time. Draw is called only after Update.
#if RENDER_PROFILING || GPU_PROFILING
                IsFixedTimeStep = false;
                MyMinerGame.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
#else
                IsFixedTimeStep = MyFakes.FIXED_TIMESTEP;
#endif
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitMultithreading");

            InitMultithreading();
#if !DEBUG
        }

        catch (Exception ex)
        {
            //  We are catching exceptions in constructor, because if error occures here, it app will start unloading
            //  so we skip to UnloadContent and there we will get another exception (because app wasn't really loaded when unload started)
            //  So we want original exception in log.
            MyMwcLog.WriteLine(ex);
            throw;
        }
#endif

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.Constructor() - END");
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
        /// <summary>
        /// CreatePrefab
        /// </summary>
        /// <param name="hudLabelText"></param>
        /// <param name="objBuilder"></param>
        /// <returns></returns>
        public MyPrefabBase CreatePrefab(string hudLabelText, MyPrefabContainer prefabContainer, MyMwcObjectBuilder_PrefabBase prefabBuilder)
        {
            Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyPrefabFactory.CreatePrefab");

            MyPrefabConfiguration config   = MyPrefabConstants.GetPrefabConfiguration(prefabBuilder.GetObjectBuilderType(), prefabBuilder.GetObjectBuilderId().Value);
            Vector3 relativePosition       = MyPrefabContainer.GetRelativePositionInAbsoluteCoords(prefabBuilder.PositionInContainer);
            Matrix  prefabLocalOrientation = Matrix.CreateFromYawPitchRoll(prefabBuilder.AnglesInContainer.X, prefabBuilder.AnglesInContainer.Y, prefabBuilder.AnglesInContainer.Z);

            MyPrefabBase prefab = null;

            if (config is MyPrefabConfigurationKinematic)
            {
                prefab = new MyPrefabKinematic(prefabContainer);
            }
            else if (config is MyPrefabConfigurationLight)
            {
                prefab = new MyPrefabLight(prefabContainer);
            }
            else if (config is MyPrefabConfigurationLargeWeapon)
            {
                prefab = new MyPrefabLargeWeapon(prefabContainer);
            }
            else if (config is MyPrefabConfigurationSound)
            {
                prefab = new MyPrefabSound(prefabContainer);
            }
            else if (config is MyPrefabConfigurationParticles)
            {
                prefab = new MyPrefabParticles(prefabContainer);
            }
            else if (config is MyPrefabConfigurationLargeShip)
            {
                prefab = new MyPrefabLargeShip(prefabContainer);
            }
            else if (config is MyPrefabConfigurationHangar)
            {
                prefab = new MyPrefabHangar(prefabContainer);
            }
            else if (config is MyPrefabConfigurationFoundationFactory)
            {
                prefab = new MyPrefabFoundationFactory(prefabContainer);
            }
            else if (config is MyPrefabConfigurationSecurityControlHUB)
            {
                prefab = new MyPrefabSecurityControlHUB(prefabContainer);
            }
            else if (config is MyPrefabConfigurationBankNode)
            {
                prefab = new MyPrefabBankNode(prefabContainer);
            }
            else if (config is MyPrefabConfigurationGenerator)
            {
                prefab = new MyPrefabGenerator(prefabContainer);
            }
            else if (config is MyPrefabConfigurationScanner)
            {
                prefab = new MyPrefabScanner(prefabContainer);
            }
            else if (config is MyPrefabConfigurationCamera)
            {
                prefab = new MyPrefabCamera(prefabContainer);
            }
            else if (config is MyPrefabConfigurationAlarm)
            {
                prefab = new MyPrefabAlarm(prefabContainer);
            }
            else
            {
                prefab = new MyPrefab(prefabContainer);
                //prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config);
            }
            prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config);

            Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            return(prefab);
        }