Exemplo n.º 1
0
        protected override bool OnCreate()
        {
            instance = this;

            ChangeToBetterDefaultSettings();

            if (!base.OnCreate())
            {
                return(false);
            }

            SoundVolume = soundVolume;
            MusicVolume = musicVolume;

            controlManager = new ScreenControlManager(ScreenGuiRenderer);
            if (!ControlsWorld.Init())
            {
                return(false);
            }

            _ShowSystemCursor = _ShowSystemCursor;
            _DrawFPS          = _DrawFPS;
            MaterialScheme    = materialScheme;

            Log.Handlers.InfoHandler    += Log_Handlers_InfoHandler;
            Log.Handlers.WarningHandler += Log_Handlers_WarningHandler;
            Log.Handlers.ErrorHandler   += Log_Handlers_ErrorHandler;
            Log.Handlers.FatalHandler   += Log_Handlers_FatalHandler;

            //Camera
            Camera camera = RendererWorld.Instance.DefaultCamera;

            camera.NearClipDistance = .1f;
            camera.FarClipDistance  = 1000.0f;
            camera.FixedUp          = Vec3.ZAxis;
            camera.Fov      = 90;
            camera.Position = new Vec3(-10, -10, 10);
            camera.LookAt(new Vec3(0, 0, 0));

            EControl programLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                "Gui\\ProgramLoadingWindow.gui");

            if (programLoadingWindow != null)
            {
                controlManager.Controls.Add(programLoadingWindow);
            }

            //Subcribe to callbacks during engine loading. We will render scene from callback.
            LongOperationCallbackManager.Subscribe(LongOperationCallbackManager_LoadingCallback,
                                                   programLoadingWindow);

            if (!HighLevelMaterialManager.Instance.LoadAllMaterials())
            {
                LongOperationCallbackManager.Unsubscribe();
                return(true);
            }

            RenderScene();

            //Game controls
            GameControlsManager.Init();

            //EntitySystem
            if (!EntitySystemWorld.Init(new EntitySystemWorld()))
            {
                LongOperationCallbackManager.Unsubscribe();
                return(true);
            }

            LongOperationCallbackManager.Unsubscribe();

            //close loading window.
            if (programLoadingWindow != null)
            {
                programLoadingWindow.SetShouldDetach();
            }

            string mapName = "";

            if (autorunMapName != "" && autorunMapName.Length > 2)
            {
                mapName = autorunMapName;
                if (!mapName.Contains("\\") && !mapName.Contains("/"))
                {
                    mapName = "Maps/" + mapName + "/Map.map";
                }
            }

            if (!WebPlayerMode)
            {
                string[] commandLineArgs = Environment.GetCommandLineArgs();
                if (commandLineArgs.Length > 1)
                {
                    string name = commandLineArgs[1];
                    if (name[0] == '\"' && name[name.Length - 1] == '\"')
                    {
                        name = name.Substring(1, name.Length - 2);
                    }
                    name = name.Replace('/', '\\');

                    string dataDirectory = VirtualFileSystem.ResourceDirectoryPath;
                    dataDirectory = dataDirectory.Replace('/', '\\');

                    if (name.Length > dataDirectory.Length)
                    {
                        if (string.Compare(name.Substring(0, dataDirectory.Length), dataDirectory, true) == 0)
                        {
                            name = name.Substring(dataDirectory.Length + 1);
                        }
                    }

                    mapName = name;
                }
            }

            if (mapName != "")
            {
                if (!ServerOrSingle_MapLoad(mapName, EntitySystemWorld.Instance.DefaultWorldType, false))
                {
                    //Error
                    foreach (EControl control in controlManager.Controls)
                    {
                        if (control is MessageBoxWindow && !control.IsShouldDetach())
                        {
                            return(true);
                        }
                    }

                    GameMusic.MusicPlay("Sounds\\Music\\MainMenu.ogg", true);
                    controlManager.Controls.Add(new EngineLogoWindow());
                }
            }
            else
            {
                GameMusic.MusicPlay("Sounds\\Music\\MainMenu.ogg", true);
                controlManager.Controls.Add(new EngineLogoWindow());
            }

            //showDebugInformation console command
            if (EngineConsole.Instance != null)
            {
                EngineConsole.Instance.AddCommand("showDebugInformationWindow",
                                                  ConsoleCommand_ShowDebugInformationWindow);
            }

            //example of custom input device
            //ExampleCustomInputDevice.InitDevice();

            return(true);
        }
Exemplo n.º 2
0
        public bool ServerOrSingle_MapLoad(string fileName, WorldType worldType,
                                           bool noChangeWindows)
        {
            GameNetworkServer server = GameNetworkServer.Instance;

            EControl mapLoadingWindow = null;

            //show map loading window
            if (!noChangeWindows)
            {
                mapLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                    "Gui\\MapLoadingWindow.gui");
                if (mapLoadingWindow != null)
                {
                    mapLoadingWindow.Text = fileName;
                    controlManager.Controls.Add(mapLoadingWindow);
                }
                RenderScene();
            }

            DeleteAllGameWindows();

            MapSystemWorld.MapDestroy();

            //create world if need
            if (World.Instance == null || World.Instance.Type != worldType)
            {
                WorldSimulationTypes worldSimulationType;
                EntitySystemWorld.NetworkingInterface networkingInterface = null;

                if (server != null)
                {
                    worldSimulationType = WorldSimulationTypes.ServerAndClient;
                    networkingInterface = server.EntitySystemService.NetworkingInterface;
                }
                else
                {
                    worldSimulationType = WorldSimulationTypes.Single;
                }

                if (!EntitySystemWorld.Instance.WorldCreate(worldSimulationType, worldType,
                                                            networkingInterface))
                {
                    Log.Fatal("GameEngineApp: MapLoad: EntitySystemWorld.WorldCreate failed.");
                }
            }

            //Subcribe to callbacks during map loading. We will render scene from callback.
            LongOperationCallbackManager.Subscribe(LongOperationCallbackManager_LoadingCallback,
                                                   mapLoadingWindow);

            //load map
            if (!MapSystemWorld.MapLoad(fileName))
            {
                if (mapLoadingWindow != null)
                {
                    mapLoadingWindow.SetShouldDetach();
                }

                LongOperationCallbackManager.Unsubscribe();

                return(false);
            }

            //inform clients about world created
            if (server != null)
            {
                server.EntitySystemService.InformClientsAfterWorldCreated();
            }

            //Simulate physics for 5 seconds. That the physics has fallen asleep.
            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
            {
                SimulatePhysicsForLoadedMap(5);
            }

            //Update shadow settings. This operation can be slow because need update all
            //shaders if shadow technique changed.
            Map.Instance.UpdateSceneManagerShadowSettings();

            fullscreenFadingRemainingFrames = 35;

            LongOperationCallbackManager.Unsubscribe();

            //Error
            foreach (EControl control in controlManager.Controls)
            {
                if (control is MessageBoxWindow && !control.IsShouldDetach())
                {
                    return(false);
                }
            }

            if (!noChangeWindows)
            {
                CreateGameWindowForMap();
            }

            //play music
            if (!noChangeWindows)
            {
                if (GameMap.Instance != null)
                {
                    GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
                }
            }

            EntitySystemWorld.Instance.ResetExecutedTime();

            return(true);
        }
Exemplo n.º 3
0
        public bool WorldLoad(string fileName)
        {
            EControl worldLoadingWindow = null;

            //world loading window
            {
                worldLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                    "Gui\\WorldLoadingWindow.gui");
                if (worldLoadingWindow != null)
                {
                    worldLoadingWindow.Text = fileName;
                    controlManager.Controls.Add(worldLoadingWindow);
                }
                RenderScene();
            }

            DeleteAllGameWindows();

            //Subcribe to callbacks during engine loading. We will render scene from callback.
            LongOperationCallbackManager.Subscribe(LongOperationCallbackManager_LoadingCallback,
                                                   worldLoadingWindow);

            if (!MapSystemWorld.WorldLoad(WorldSimulationTypes.Single, fileName))
            {
                if (worldLoadingWindow != null)
                {
                    worldLoadingWindow.SetShouldDetach();
                }

                LongOperationCallbackManager.Unsubscribe();

                return(false);
            }

            //Update shadow settings. This operation can be slow because need update all
            //shaders if shadow technique changed.
            Map.Instance.UpdateSceneManagerShadowSettings();

            fullscreenFadingRemainingFrames = 35;

            LongOperationCallbackManager.Unsubscribe();

            //Error
            foreach (EControl control in controlManager.Controls)
            {
                if (control is MessageBoxWindow && !control.IsShouldDetach())
                {
                    return(false);
                }
            }

            //create game window
            CreateGameWindowForMap();

            //play music
            if (GameMap.Instance != null)
            {
                GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
            }

            return(true);
        }