Ejemplo n.º 1
0
    public void TerminateGameSession(bool TransitionToMainMenu = false)
    {
        if (_gameSession != null)
        {
            _gameSession.Destroy();
            _gameSession = null;
        }

        if (TransitionToMainMenu)
        {
            UIManager.AddInterface(new CMainMenuUI());
        }

        // TODO: Game UI needs to f**k off.
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Game startup.
    /// </summary>
    public CGame(CUnityInterface Interface, string CommandLineArgs)
    {
        _cmdArgs = CommandLineArgs.Split(' ');
        string[] parms;

#if !UNITY_EDITOR
        DataDirectory           = Application.dataPath + "/Data/";
        PersistentDataDirectory = Application.persistentDataPath + "/";
#else
        DataDirectory           = "Data/";
        PersistentDataDirectory = "SaveData/";
#endif

        Config = new CConfig(PersistentDataDirectory + "config.txt");
        Config.Load();

#if !UNITY_EDITOR
        DataDirectory           = Application.dataPath + "/Data/";
        PersistentDataDirectory = Application.persistentDataPath + "/";

        if (_CheckArg("dev", out parms))
        {
            Screen.SetResolution(1280, 720, false);
        }
        else
        {
            string resType = Config.GetString("ResolutionType");

            if (resType == "default")
            {
                Resolution r = Screen.resolutions[Screen.resolutions.Length - 1];
                Screen.SetResolution(r.width, r.height, true);
            }
            else if (resType == "fullscreen" || resType == "windowed")
            {
                Resolution r    = Screen.resolutions[Screen.resolutions.Length - 1];
                int        resX = (int)Config.GetFloat("ResolutionWidth");
                int        resY = (int)Config.GetFloat("ResolutionHeight");

                Screen.SetResolution(resX, resY, (resType == "fullscreen"));
            }
        }
#endif

        CUtility.MakeDirectory(PersistentDataDirectory + SAVES_DIRECTORY);
        CUtility.MakeDirectory(PersistentDataDirectory + REPLAYS_DIRECTORY);

        PrimaryResources = Interface.GetComponent <CPrimaryResources>();
        WorldResources   = Interface.GetComponent <CWorldResources>();
        UIResources      = Interface.GetComponent <CUIResources>();
        ToolkitUI        = Interface.GetComponent <CToolkitUI>();
        GameUIStyle      = Interface.GetComponent <CGameUIStyle>();

        Console = new CConsole();

        Debug.Log("Save game directory: " + PersistentDataDirectory);
        Debug.Log("Data directory: " + DataDirectory);

        VarShowGrid        = Console.CreateVar("show_grid", false);
        VarShowVisLines    = Console.CreateVar("show_los", false);
        VarShowDDATest     = Console.CreateVar("show_ddatest", false);
        VarShowArcTest     = Console.CreateVar("show_arctest", false);
        VarShowBounds      = Console.CreateVar("show_bounds", false);
        VarShowDebugStats  = Console.CreateVar("show_debugstats", false);
        VarShowMobility    = Console.CreateVar("show_mobility", 0, 0, CWorld.MAX_PLAYERS);
        VarShowSolidity    = Console.CreateVar("show_solidity", 0, 0, CWorld.MAX_PLAYERS + 1);
        VarShowProfiler    = Console.CreateVar("show_profiler", false);
        VarNoFow           = Console.CreateVar("no_fow", false);
        VarPlaceItemDirect = Console.CreateVar("place_item_direct", false);
        VarShowComfort     = Console.CreateVar("show_comfort", false);
        VarShowEfficiency  = Console.CreateVar("show_efficiency", false);

        VarShowPathing   = Console.CreateVar("pathing", false);
        VarShowFlowField = Console.CreateVar("show_flowfield", false);
        VarShowNavMesh   = Console.CreateVar("show_navmesh", false);
        VarShowNavRect   = Console.CreateVar("show_navrect", 0, 0, CWorld.MAX_PLAYERS);
        VarShowProxies   = Console.CreateVar("show_proxies", 0, 0, CWorld.MAX_PLAYERS);

        VarFreePurchases = Console.CreateVar("freebuy", true);
        Console.CreateCommand("gameui", (Params) => { UIManager.ToggleUIActive(); });
        Console.CreateCommand("quit", (Params) => { ExitApplication(); });
        Console.CreateCommand("exit", (Params) => { ExitApplication(); });
        Console.CreateCommand("set_owed", (Params) => { if (_gameSession == null)
                                                        {
                                                            return;
                                                        }
                                                        _gameSession.SetOwed(1000); });
        Console.CreateCommand("set_stamina", (Params) => { if (_gameSession == null)
                                                           {
                                                               return;
                                                           }
                                                           _gameSession.SetStamina(10.0f); });
        Console.CreateCommand("set_hunger", (Params) => { if (_gameSession == null)
                                                          {
                                                              return;
                                                          }
                                                          _gameSession.SetHunger(80); });
        Console.CreateCommand("rebuild_icons", (Params) => { IconBuilder.RebuildItemIcons(true); });

        Game  = this;
        Steam = new CSteam();
        PrimaryThreadProfiler = new CProfiler();
        SimThreadProfiler     = new CProfiler();
        DebugLevels           = new CDebugLevels();
        UniversalRandom       = new CRandomStream();
        AssetManager          = new CAssetManager();
        Net           = new CNet();
        Resources     = new CResources();
        CameraManager = new CCameraManager();
        UIManager     = new CUIManager(ToolkitUI, GameUIStyle);
        CDebug.StaticInit();
        AssetManager.Init();
        ProfilerManager = new CProfilerManager();
        ProfilerManager.Init();
        IconBuilder = new CIconBuilder();
        IconBuilder.Init();
        _inputState = new CInputState();

        Console.Hide();
        Analytics.SetUserId(Steam.mSteamID.ToString());

        // TODO: Backquote is not ~, investigate.
        // TOOD: Allow the same command to have multiple keys associated with it.
        _inputState.RegisterCommand("console", Config.GetString("KeyConsole"), true);

        _inputState.RegisterCommand("escape", Config.GetString("KeyEscape"));

        _inputState.RegisterCommand("focusOnSpawn", Config.GetString("KeyFocusOnSpawn"));

        _inputState.RegisterCommand("camForward", Config.GetString("KeyCamForward"));
        _inputState.RegisterCommand("camLeft", Config.GetString("KeyCamLeft"));
        _inputState.RegisterCommand("camBackward", Config.GetString("KeyCamBackward"));
        _inputState.RegisterCommand("camRight", Config.GetString("KeyCamRight"));
        _inputState.RegisterCommand("camRotateLeft", KeyCode.Delete);
        _inputState.RegisterCommand("camRotateRight", KeyCode.PageDown);

        _inputState.RegisterCommand("itemPlaceRotate", Config.GetString("KeyPlaceRotate"));
        _inputState.RegisterCommand("itemPlaceRepeat", Config.GetString("KeyPlaceRepeat"));

        _inputState.RegisterCommand("action1", Config.GetString("KeyAction1"));
        _inputState.RegisterCommand("action2", Config.GetString("KeyAction2"));
        _inputState.RegisterCommand("action3", Config.GetString("KeyAction3"));
        _inputState.RegisterCommand("action4", Config.GetString("KeyAction4"));

        _inputState.RegisterCommand("openOptions", Config.GetString("KeyOptionsMenu"));

        _inputState.RegisterCommand("reload", KeyCode.F5);
        _inputState.RegisterCommand("space", KeyCode.Space);

        _inputState.RegisterCommand("editorDelete", Config.GetString("KeyEditorDelete"));
        _inputState.RegisterCommand("editorDuplicate", Config.GetString("KeyEditorDuplicate"));
        _inputState.RegisterCommand("editorUndo", Config.GetString("KeyEditorUndo"));
        _inputState.RegisterCommand("editorRedo", Config.GetString("KeyEditorRedo"));
        _inputState.RegisterCommand("editorSave", Config.GetString("KeyEditorSave"));

        // Apply default settings
        //Application.targetFrameRate = 60;
        //QualitySettings.antiAliasing

        // Volume range: 0.0 - -80.0
        // TODO: Volume in DB is exponential, making 0 to 1 range for config ineffective.
        UIResources.MasterMixer.SetFloat("MasterVolume", CMath.MapRangeClamp(Config.GetFloat("MasterVolume"), 0, 1, -80, -12));
        UIResources.MasterMixer.SetFloat("MusicVolume", CMath.MapRangeClamp(Config.GetFloat("MusicVolume"), 0, 1, -80, 0));
        UIResources.MasterMixer.SetFloat("SoundsVolume", CMath.MapRangeClamp(Config.GetFloat("SoundsVolume"), 0, 1, -80, 0));
        UIResources.MasterMixer.SetFloat("UISoundsVolume", CMath.MapRangeClamp(Config.GetFloat("UISoundsVolume"), 0, 1, -80, 0));

        // NOTE: BE SUPER CAREFUL WITH THIS
        // You can corrupt ALL the item assets if not careful.
        // Saves asset to disk, but asset currently in memory won't reflect new version.
        //_resaveAllItemAssetsToLastestVersion();

        // TODO: This bootstraps all model assets on startup.
        // If the model asset is first loaded by the sim thread, then it will crash as it tries to generate the meshes.
        // Should probably only generate meshes when they are pulled in by the main thread.
        _testItemAssetVersion();

        if (_CheckArg("toolkit", out parms))
        {
            StartAssetToolkit();
        }
        else if (_CheckArg("map", out parms))
        {
            if (parms != null && parms.Length > 0)
            {
                CGameSession.CStartParams startParams = new CGameSession.CStartParams();
                startParams.mPlayType        = CGameSession.EPlayType.SINGLE;
                startParams.mUserPlayerIndex = 0;                 // Will be set by the level when loaded.
                startParams.mLevelName       = parms[0];
                StartGameSession(startParams);
            }
        }
        else
        {
            UIManager.AddInterface(new CMainMenuUI());
        }
    }