示例#1
0
 public Mod(string path, ModSource source)
 {
     Path   = path;
     Source = source;
     if (File.Exists(Path) && Path.EndsWith(".zip"))
     {
         m_contents = new ZipArchiveFileStore(Path, "");
         m_assets   = new FileAssetSource("Untitled Mod", new ZipArchiveFileStore(Path, "assets"));
     }
     else if (Directory.Exists(Path))
     {
         m_contents = new FolderFileStore(Path);
         m_assets   = new FileAssetSource("Untitled Mod", new FolderFileStore(System.IO.Path.Combine(Path, "assets")));
     }
     else
     {
         m_contents = null;
         m_assets   = new FileAssetSource("Untitled Mod", new EmptyFileStore());
     }
     m_assets.Mod = this;
     ReloadInfo();
     Loaded = false;
 }
示例#2
0
        private void Load()
        {
            // Bind OpenGL
            m_window.MakeCurrent();

            // Set default OpenGL options
            GL.Viewport(0, 0, Window.Width, Window.Height);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.DepthMask(true);

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Greater, 0.0f);

            GL.LineWidth(2.0f);

            // Create render stuff
            var width  = Math.Min(Window.Width, User.Settings.FullscreenWidth);
            var height = Math.Min(Window.Height, User.Settings.FullscreenHeight);
            var aamode = User.Settings.AAMode;

            m_postEffect       = new PostEffectInstance(User.Settings);
            m_postEffect.Gamma = User.Settings.Gamma;

            int scale = (aamode == AntiAliasingMode.SSAA) ? 2 : 1;

            m_worldRenderTexture   = new RenderTexture(scale * width, scale * height, true);
            m_upscaleEffect        = new UpscaleEffectInstance();
            m_backgroundEffect     = new BackgroundEffectInstance();
            m_upscaleRenderTexture = new RenderTexture(width, height, true);
            m_fullScreenQuad       = CreateFullscreenQuad();
            m_cameraAxisMarker     = new AxisMarker();

            // Create camera
            var aspectRatio = (float)Window.Width / (float)Window.Height;

            m_camera = new Camera(Matrix4.Identity, DEFAULT_FOV, aspectRatio);

            // Create screen
            m_screen = new Screen(
                Mouse, Keyboard, Language, m_window, m_audio,
                aspectRatio * SCREEN_HEIGHT, SCREEN_HEIGHT,
                width, height
                );

            m_cursor         = new Cursor();
            m_cursor.Visible = false;
            m_screen.Elements.Add(m_cursor);

            m_debugMenu         = new DebugMenu(this);
            m_debugMenu.Visible = false;
            m_screen.Elements.Add(m_debugMenu);

            // Add the rest of the asset sources:
            // Add the base assets
            var baseAssetFileStore = new FolderFileStore(Path.Combine(App.AssetPath, "base"));
            var baseAssets         = new FileAssetSource("base", baseAssetFileStore);

            Assets.AddSource(baseAssets);

            // Add the main assets
            var mainAssetFileStore = new FolderFileStore(Path.Combine(App.AssetPath, "main"));
            var mainAssets         = new FileAssetSource("main", mainAssetFileStore);

            Assets.AddSource(mainAssets);

            // Add the temp assets (used by the editor)
            var tempAssetFileStore = new LocatedFileStore(
                new FolderFileStore(Path.Combine(App.SavePath, "editor/temp")),
                "temp"
                );
            var tempAssets = new FileAssetSource("temp", tempAssetFileStore);

            Assets.AddSource(tempAssets);

            // Add autoload mod assets
            foreach (Mod mod in Mods.AllMods)
            {
                if (mod.AutoLoad)
                {
                    Assets.AddSource(mod.Assets);
                    mod.Loaded = true;
                }
            }

            // Create initial loading state
            m_currentState = CreateInitialState();
            m_pendingState = null;
            m_currentState.PreInit(null, null);
            m_currentState.Reveal();
            m_currentState.Init();
        }
示例#3
0
        public Game()
        {
            m_promiseTasks = new List <PromiseTask>();

            m_over         = false;
            RenderUI       = true;
            UseDebugCamera = false;

            // Init network
            if (App.Steam)
            {
                m_network = new SteamworksNetwork(
                    AchievementExtensions.GetAllIDs(),
                    StatisticExtensions.GetAllIDs()
                    );
            }
            else
            {
                m_network = new BuiltinNetwork();
            }
            if (m_network.SupportsAchievements)
            {
                m_network.SetAchievementCorner(AchievementCorner.TopRight);
            }

            // Init user
            m_user = LoadUser();

            // Init window
            var title = App.Info.Title + " " + App.Info.Version.ToString();

            if (App.Debug && App.Steam)
            {
                title += " (Steam Debug build)";
            }
            else if (App.Debug)
            {
                title += " (Debug build)";
            }

            bool fullscreen = m_user.Settings.Fullscreen;
            bool vsync      = m_user.Settings.VSync;

            using (var icon = new Bitmap(Path.Combine(App.AssetPath, "icon.png")))
            {
                m_window = new SDL2Window(
                    title,
                    m_user.Settings.WindowWidth,
                    m_user.Settings.WindowHeight,
                    m_user.Settings.Fullscreen,
                    m_user.Settings.WindowMaximised,
                    m_user.Settings.VSync
                    );
                m_window.SetIcon(icon);
            }
            m_window.OnClosed += delegate(object sender, EventArgs e)
            {
                Over = true;
            };
            m_window.OnResized += delegate(object sender, EventArgs e)
            {
                Resize();
                if (!m_window.Fullscreen)
                {
                    if (m_window.Maximised)
                    {
                        m_user.Settings.WindowMaximised = true;
                    }
                    else
                    {
                        m_user.Settings.WindowMaximised = false;
                        m_user.Settings.WindowWidth     = m_window.Width;
                        m_user.Settings.WindowHeight    = m_window.Height;
                    }
                    m_user.Settings.Save();
                }
            };

            // Init audio
            if (App.Arguments.GetBool("nosound"))
            {
                m_audio = new NullAudio();
            }
            else
            {
                m_audio = new OpenALAudio();
            }
            m_audio.EnableSound = m_user.Settings.EnableSound;
            m_audio.SoundVolume = m_user.Settings.SoundVolume / 11.0f;
            m_audio.EnableMusic = m_user.Settings.EnableMusic;
            m_audio.MusicVolume = m_user.Settings.MusicVolume / 11.0f;
            m_gameAudio         = new GameAudio(m_audio);

            // Init input
            m_keyboard      = new SDL2Keyboard(m_window);
            m_mouse         = new SDL2Mouse(m_window);
            m_gamepads      = new SDL2GamepadCollection(m_window);
            m_activeGamepad = null;
            if (App.Steam)
            {
                m_steamControllers = new SteamworksSteamControllerCollection(
                    m_window,
                    SteamControllerActionSetExtensions.GetAllIDs(),
                    SteamControllerButtonExtensions.GetAllIDs(),
                    SteamControllerJoystickExtensions.GetAllIDs(),
                    SteamControllerAxisExtensions.GetAllIDs()
                    );
                m_readOnlySteamControllers = m_steamControllers;
                m_activeSteamController    = null;
            }
            else
            {
                m_steamControllers         = null;
                m_readOnlySteamControllers = new List <ISteamController>(0).ToReadOnly();
                m_activeSteamController    = null;
            }

            // Init tiles
            Tiles.Init();

            // Load early assets
            var earlyAssetFileStore = new FolderFileStore(Path.Combine(App.AssetPath, "early"));
            var earlyAssets         = new FileAssetSource("early", earlyAssetFileStore);

            Assets.AddSource(earlyAssets);
            Assets.LoadAll();

            // Find mods
            Mods.Refresh(Network);
            if (Network.SupportsWorkshop)
            {
                // See if any mods are worthy of the popular mod achievement
                var myModIDs = new List <ulong>();
                foreach (var mod in Mods.AllMods)
                {
                    if (mod.Source == ModSource.Editor &&
                        mod.SteamWorkshopID.HasValue)
                    {
                        myModIDs.Add(mod.SteamWorkshopID.Value);
                    }
                }
                if (myModIDs.Count > 0)
                {
                    QueuePromiseTask(
                        m_network.Workshop.GetItemInfo(myModIDs.ToArray()),
                        delegate(Promise <WorkshopItemInfo[]> result)
                    {
                        if (result.Status == Status.Complete)
                        {
                            var infos = result.Result;
                            int subs  = 0;
                            for (int i = 0; i < infos.Length; ++i)
                            {
                                var info = infos[i];
                                if (info.AuthorID == m_network.LocalUser.ID &&
                                    info.UpVotes >= info.DownVotes)
                                {
                                    subs = Math.Max(info.TotalSubscribers, subs);
                                }
                            }
                            int oldSubs = User.Progress.GetStatistic(Statistic.MostPopularModSubscriptions);
                            if (subs >= 25)
                            {
                                User.Progress.SetStatistic(Statistic.MostPopularModSubscriptions, subs);
                                User.Progress.UnlockAchievement(Achievement.CreatePopularMod);
                                User.Progress.Save();
                            }
                            else if (subs > oldSubs)
                            {
                                User.Progress.SetStatistic(Statistic.MostPopularModSubscriptions, subs);
                                User.Progress.IndicateAchievementProgress(Achievement.CreatePopularMod, subs, 25);
                                User.Progress.Save();
                            }
                        }
                    }
                        );
                }
            }

            // Load language
            SelectLanguage();

            // Load debug stuff
            m_debugCameraController = new DebugCameraController(this);

            // Load game
            Load();
        }