public ScriptedEntityNode()
 {
     _name = "Scripted Entity";
     _process = new ScriptExecutionProcess(this);
     ProcessManager.AttachProcess(_process);
     SyncCollisionEvents();
 }
示例#2
0
        /// <summary>
        ///     Entry point of the map loading thread.
        /// </summary>
        protected void LoadMapThread()
        {
            // Ignore everything else if we are not running a game.
            if (_gameName == "")
                return;

            // Kill of old processes.
            ArrayList disposeList = new ArrayList();
            foreach (Process process in ProcessManager.Processes)
                if (process.IsPersistent == false) disposeList.Add(process);
            foreach (Process process in disposeList)
            {
                ProcessManager.DettachProcess(process);
                process.Dispose();
            }

            // Remove process / media  references from scripts?
            // Unneccessary?

            // Load the map.
            _map.Load(_mapLoadFile, _mapLoadPassword, null, true, true);

            // Remove the map path part.
            string mapScriptURL = Path.ChangeExtension(_mapLoadFile, ".fs");
            if (mapScriptURL.ToLower().StartsWith(_mapPath.ToLower() + "\\"))
                mapScriptURL = mapScriptURL.Substring(_mapPath.Length + 1);

            // Check if the map script exists.
            if (ResourceManager.ResourceExists(_mapScriptPath + "\\" + mapScriptURL) == true)
            {
                // It does, w00t, lets create an execution process for it then.
                _mapScriptProcess = new ScriptExecutionProcess(_mapScriptPath + "\\" + mapScriptURL);
                if (_mapScriptProcess.Process != null)
                {
                    _mapScriptProcess.Priority = 999999; // Always runs first, otherwise all hell breaks loose with the OnCreate events.
                    _mapScriptProcess.Process.OnStateChange += OnStateChange;
                    ProcessManager.AttachProcess(_mapScriptProcess);

                    OnStateChange(_mapScriptProcess.Process, _mapScriptProcess.Process.State);
                }
            }

            // Tell the scripts that we are now loading the new map (so they can show a loadings screen).
            _gameScriptProcess.Process.InvokeFunction("OnLoadingFinish", true, true);

            // Pump out a MapBegin event.
            EventManager.FireEvent(new Event("map_begin", this, null));
        }
        /// <summary>
        ///     Responsable for removing references of this object and deallocated
        ///     resources that have been allocated.
        /// </summary>
        public override void Dispose()
        {
            // Call the abstracted base method to clean up general things.
            base.Dispose();

            // Dispose of the execution process.
            if (_process != null)
            {
                ProcessManager.DettachProcess(_process);
                _process.Finish(ProcessResult.Failed);
                _process.Dispose();
                _process = null;
                //_process.Dispose();
            }
        }
示例#4
0
        /// <summary>
        ///		Called by the base engine class when its safe to begin initialization.
        /// </summary>
        protected override bool Begin()
        {
            Runtime.Debug.DebugLogger.WriteLog("Entered begin function", LogAlertLevel.Warning);
            // Create the fusion fuction set.
            new FusionFunctionSet();
            new NetworkFunctionSet();

            // Bind all function sets to the global virtual machine.
            NativeFunctionSet.RegisterCommandSetsToVirtualMachine(VirtualMachine.GlobalInstance);

            // Grab some config out of the games config file.
            ASCIIEncoding encoding = new ASCIIEncoding();
            _currentPassword = _engineConfigFile["account:password", ""];
            _currentUsername = _engineConfigFile["account:username", ""];

            // Make sure we have a game we can run.
            if (_gameName != "")
            {
                // Create the loading window thread.
                _loading = true;
                new Thread(LoadingWindowThread).Start();

                NetworkManager.IsServer = _isServer;

                if (_isServer == false)
                {
                    // Setup graphics window.
                    SetupGameWindow();
                }
                else
                {
                    // Setup graphics window. We are only actually doing this so the graphics and audio drivers have something to bind to.
                    // Notice that we are hiding it as soon as its made.
                    SetupGameWindow();
                    _window.Hide();

                    // Setup server window.
                    _serverWindow = new ServerWindow();
                    _serverWindow.FormClosing += new FormClosingEventHandler(OnClosing);
                    _serverWindow.Show();

                    // Setup server.
                    if (NetworkManager.Start() == false)
                    {
                        throw new Exception("An error occured while attempting to setup network.");
                    }
                }

                // Create some hooks into network events.
                NetworkManager.ClientConnected += new ClientConnectedEventHandler(ClientConnected);
                NetworkManager.ClientDisconnected += new ClientDisconnectedEventHandler(ClientDisconnected);
                NetworkManager.Disconnected += new DisconnectedEventHandler(Disconnected);
                NetworkManager.PacketRecieved += new PacketRecievedEventHandler(PacketRecieved);

                // If pak files are being used then load all of them in and register
                // them with the resource manager
                if (_usePakFiles == true)
                {
                    ResourceManager.UsePakFiles = true;
                    DebugLogger.WriteLog("Looking for resources in pak files...");
                    foreach (string file in Directory.GetFiles(Environment.CurrentDirectory))
                        if (file.ToLower().EndsWith(".pk") == true)
                        {
                            DebugLogger.WriteLog("Looking for resources in \"" + Path.GetFileName(file) + "\"...");
                            PakFile pakFile = new PakFile(file);
                            ResourceManager.RegisterPakFile(pakFile);
                        }
                }

                // Load in the default tileset if it exists and add it to the tileset list.
                if (ResourceManager.ResourceExists(_tilesetPath + "\\default.xml") == true)
                {
                    DebugLogger.WriteLog("Found default tileset, loading...");
                    Tileset.AddToTilesetPool(new Tileset(_tilesetPath + "\\default.xml"));
                }

                // Load in the default font if it exists.
                if (ResourceManager.ResourceExists(_fontPath + "\\default.xml") == true)
                {
                    DebugLogger.WriteLog("Found default bitmap font, loading...");
                    GraphicsManager.DefaultBitmapFont = new BitmapFont(_fontPath + "\\default.xml");
                }

                // Load in the required language pack.
                string languageFile = _languagePath + "\\" + _language + ".xml";
                if (ResourceManager.ResourceExists(languageFile) == true)
                {
                    DebugLogger.WriteLog("Loading language pack for language " + _language + ".");
                    LanguageManager.LoadLanguagePack(_languagePath + "\\" + _language + ".xml", _language);
                }
                else
                   DebugLogger.WriteLog("Unable to find language pack for language " + _language + ".", LogAlertLevel.Error);

                // Register the console commands, incase we turn the console on later.
                new StatisticalConsoleCommands();
                new FusionConsoleCommands();
                new MapConsoleCommands();
                new SystemConsoleCommands();

                // Register all the command sets with the console.
                ConsoleCommandSet.RegisterCommandSets();

                // Shall we setup the graphical console?
                if (_showConsole == true && _isServer == false)
                {
                    // Enable the graphical console.
                    GraphicalConsole.Enabled = true;
                }

                // Check if the start script exists.
                if (ResourceManager.ResourceExists(_startScript) == true)
                {
                    // It does, w00t, lets create an execution process for it then.
                    _gameScriptProcess = new ScriptExecutionProcess(_startScript);
                    if (_gameScriptProcess.Process != null)
                    {
                        _gameScriptProcess.Priority = 1000000; // Always runs first, otherwise all hell breaks loose with the OnCreate events.
                        _gameScriptProcess.IsPersistent = true;
                        _gameScriptProcess.Process.OnStateChange += this.OnStateChange;
                        ProcessManager.AttachProcess(_gameScriptProcess);

                        OnStateChange(_gameScriptProcess.Process, _gameScriptProcess.Process.State);
                    }
                }

                // Pump out a GameBegin event.
                EventManager.FireEvent(new Event("game_begin", this, null));

                // Close the loading window.
                _loading = false;

                // Show the game window.
                if (_isServer == false)
                {
                    _window.Show();
                    _window.BringToFront();
                    _window.Activate();
                }
                else
                {
                    _serverWindow.Show();
                    _serverWindow.BringToFront();
                    _serverWindow.Activate();
                }
            }

            // Nope? Ok show the games explorer.
            else
            {
                _explorerWindow = new GamesExplorerWindow();
                _explorerWindow.FormClosing += new FormClosingEventHandler(OnClosing);
                _explorerWindow.Show();
            }

            return false;
        }