Esempio n. 1
0
        void Log_Handlers_ErrorHandler(string text, ref bool handled)
        {
            if (controlManager != null)
            {
                handled = true;

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

                if (Map.Instance != null)
                {
                    if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
                    {
                        EntitySystemWorld.Instance.Simulation = false;
                    }
                }

                EngineApp.Instance.MouseRelativeMode = false;

                DeleteAllGameWindows();

                MapSystemWorld.MapDestroy();
                if (EntitySystemWorld.Instance != null)
                {
                    EntitySystemWorld.Instance.WorldDestroy();
                }

                GameEngineApp.Instance.Server_DestroyServer("Error on the server");
                GameEngineApp.Instance.Client_DisconnectFromServer();

                //show message box

                MessageBoxWindow messageBoxWindow = new MessageBoxWindow(text, "Error",
                                                                         delegate(EButton sender)
                {
                    //close all windows
                    foreach (EControl control in controlManager.Controls)
                    {
                        control.SetShouldDetach();
                    }

                    if (EntitySystemWorld.Instance == null)
                    {
                        EngineApp.Instance.SetNeedExit();
                        return;
                    }

                    //create main menu
                    controlManager.Controls.Add(new MainMenuWindow());
                });

                controlManager.Controls.Add(messageBoxWindow);
            }
        }
Esempio n. 2
0
        void MapDestroy(bool newMapWillBeLoaded)
        {
            bool mapWasDestroyed = Map.Instance != null;

            MapSystemWorld.MapDestroy();

            if (EntitySystemWorld.Instance != null)
            {
                EntitySystemWorld.Instance.WorldDestroy();
            }

            if (mapWasDestroyed)
            {
                GameNetworkServer.Instance.EntitySystemService.WorldWasDestroyed(newMapWillBeLoaded);
            }

            if (mapWasDestroyed)
            {
                Log("Map destroyed");
            }

            buttonMapLoad.Enabled   = true;
            buttonMapUnload.Enabled = false;
            buttonMapChange.Enabled = false;
        }
Esempio n. 3
0
        void Client_EntitySystemService_WorldCreateBegin(EntitySystemClientNetworkService sender,
                                                         WorldType worldType, string mapVirtualFileName)
        {
            //show map loading window
            EControl mapLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                "Gui\\MapLoadingWindow.gui");

            if (mapLoadingWindow != null)
            {
                mapLoadingWindow.Text = mapVirtualFileName;
                controlManager.Controls.Add(mapLoadingWindow);
            }
            RenderScene();

            DeleteAllGameWindows();

            MapSystemWorld.MapDestroy();

            if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.ClientOnly,
                                                        worldType, sender.NetworkingInterface))
            {
                Log.Fatal("GameEngineApp: Client_EntitySystemService_WorldCreateBegin: " +
                          "EntitySystemWorld.WorldCreate failed.");
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Destroys the background world.
 /// </summary>
 void DestroyMap()
 {
     if (mapInstance == Map.Instance)
     {
         MapSystemWorld.MapDestroy();
         EntitySystemWorld.Instance.WorldDestroy();
     }
 }
Esempio n. 5
0
        public static void WorldDestroy()
        {
            MapSystemWorld.MapDestroy();

            if (EntitySystemWorld.Instance != null)
            {
                EntitySystemWorld.Instance.WorldDestroy();
            }
        }
Esempio n. 6
0
        public bool MapDestroy()
        {
            if (Map.Instance == null)
            {
                return(false);
            }

            MapSystemWorld.MapDestroy();
            DestroyWorld();
            return(true);
        }
Esempio n. 7
0
        public void DestroyWorld()
        {
            EntityWorld.Instance.ClearEntitySelection(true, true);
            UndoSystem.Instance.Clear();

            CloseLogicEditor();
            MapSystemWorld.MapDestroy();
            EntitySystemWorld.Instance.WorldDestroy();

            MainForm.Instance.NotifyUpdate();   // DestroyWorld
        }
        void Client_EntitySystemService_WorldCreateBegin(EntitySystemClientNetworkService sender,
                                                         WorldType worldType, string mapVirtualFileName)
        {
            MapSystemWorld.MapDestroy();

            if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.ClientOnly,
                                                        worldType, sender.NetworkingInterface))
            {
                Log.Fatal("GameEngineApp: Client_EntitySystemService_WorldCreateBegin: " +
                          "EntitySystemWorld.WorldCreate failed.");
            }
        }
Esempio n. 9
0
 void MapDestroy()
 {
     if (Map.Instance != null)
     {
         MapSystemWorld.MapDestroy();
         Log("Map destroyed");
     }
     if (EntitySystemWorld.Instance != null)
     {
         EntitySystemWorld.Instance.WorldDestroy();
     }
 }
Esempio n. 10
0
        void exitToMainMenuButton_Click(object sender)
        {
            MapSystemWorld.MapDestroy();
            EntitySystemWorld.Instance.WorldDestroy();

            GameEngineApp.Instance.Server_DestroyServer("The server has been destroyed");
            GameEngineApp.Instance.Client_DisconnectFromServer();

            //close all windows
            foreach (Control control in GameEngineApp.Instance.ControlManager.Controls)
            {
                control.SetShouldDetach();
            }
            //create main menu
            GameEngineApp.Instance.ControlManager.Controls.Add(new MainMenuWindow());
        }
Esempio n. 11
0
        protected override void OnDestroy()
        {
            MapSystemWorld.MapDestroy();
            if (EntitySystemWorld.Instance != null)
            {
                EntitySystemWorld.Instance.WorldDestroy();
            }

            Server_DestroyServer("The server has been destroyed");
            Client_DisconnectFromServer();

            EntitySystemWorld.Shutdown();

            GameControlsManager.Shutdown();

            ControlsWorld.Shutdown();
            controlManager = null;

            EngineConsole.Shutdown();

            instance = null;
            base.OnDestroy();
        }
Esempio n. 12
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);
        }
        public static bool ServerOrSingle_MapCreate()
        {
            GameNetworkServer server = GameNetworkServer.Instance;

            Control mapLoadingWindow = null;

            //show map loading window
            mapLoadingWindow = ControlDeclarationManager.Instance.CreateControl("Gui\\MapLoadingWindow.gui");
            if (mapLoadingWindow != null)
            {
                mapLoadingWindow.Text = "Procedural map creation";
                GameEngineApp.Instance.ControlManager.Controls.Add(mapLoadingWindow);
            }

            //delete all GameWindow's
            GameEngineApp.Instance.DeleteAllGameWindows();

            MapSystemWorld.MapDestroy();

            EngineApp.Instance.RenderScene();

            //create world if need
            WorldType worldType = EntitySystemWorld.Instance.DefaultWorldType;

            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("ExampleOfProceduralMapCreation: ServerOrSingle_MapCreate: EntitySystemWorld.Instance.WorldCreate failed.");
                }
            }

            //create map
            GameMapType gameMapType = EntityTypes.Instance.GetByName("GameMap") as GameMapType;

            if (gameMapType == null)
            {
                Log.Fatal("ExampleOfProceduralMapCreation: ServerOrSingle_MapCreate: \"GameMap\" type is not defined.");
            }
            GameMap gameMap = (GameMap)Entities.Instance.Create(gameMapType, World.Instance);

            gameMap.ShadowFarDistance = 60;
            gameMap.ShadowColor       = new ColorValue(.5f, .5f, .5f);

            //create MapObjects
            ServerOrSingle_CreateEntities();

            //post create map
            gameMap.PostCreate();

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

            //Error
            foreach (Control control in GameEngineApp.Instance.ControlManager.Controls)
            {
                if (control is MessageBoxWindow && !control.IsShouldDetach())
                {
                    return(false);
                }
            }

            GameEngineApp.Instance.CreateGameWindowForMap();

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

            return(true);
        }
Esempio n. 14
0
 private void DestroyWorld()
 {
     MapSystemWorld.MapDestroy();
     EntitySystemWorld.Instance.WorldDestroy();
 }