Exemple #1
0
        /// <summary>
        /// Initialise this coordinator, specifying a collection of plugins to work with.
        /// </summary>
        /// <param name="plugins">The plugins which control this coordinator.</param>
        public Core(IOutputFactory outputFactory, params ISystemPlugin[] plugins)
        {
            try {
                mConfig = new CoreConfig();

                mPlugins            = new List <ISystemPlugin>(plugins);
                mOrientation        = new Rotation(mRotationLock, mConfig.Pitch, mConfig.Yaw);
                mOrientationDelta   = new Rotation(mRotationLock);
                mPosition           = mConfig.Position;
                mEyePosition        = mConfig.EyePosition;
                mCrashLogFile       = mConfig.CrashLogFile;
                mTickLength         = mConfig.TickLength;
                mDefaultHeight      = mConfig.HeightmapDefault;
                mHeightmap          = new float[mConfig.XRegions * 256, mConfig.YRegions * 256];
                mEnableInputUpdates = mConfig.EnableInputUpdates;

                for (int i = 0; i < mHeightmap.GetLength(0); i++)
                {
                    for (int j = 0; j < mHeightmap.GetLength(1); j++)
                    {
                        mHeightmap[i, j] = mDefaultHeight;
                    }
                }

                foreach (string frame in mConfig.Frames)
                {
                    if (outputFactory != null)
                    {
                        AddFrame(new Frame(frame, outputFactory.Create(frame)));
                    }
                    else
                    {
                        AddFrame(new Frame(frame));
                    }
                }

                foreach (var plugin in mPlugins)
                {
                    plugin.Init(this);
                    plugin.Enabled = mConfig.PluginEnabled(plugin);
                    Logger.Info("Loaded " + plugin.Name + ". " + (plugin.Enabled ? "Enabled" : "Disabled") + ".");
                }

                Thread tickThread = new Thread(TickMethod);

                tickThread.Name = "Tick Thread";
                //tickThread.Priority = ThreadPriority.Highest;
                tickThread.Start();
                mInitialised = true;
                if (InitialisationComplete != null)
                {
                    InitialisationComplete();
                }
            } catch (Exception e) {
                Logger.Warn("Unable to instantiate core. " + e.Message);
                Logger.Debug("Unable to instantiate core.", e);
            } finally {
                if (!mInitialised)
                {
                    Close();
                }
            }
        }