Ejemplo n.º 1
0
        public void Run(VRageGameServices services, IntPtr windowHandle, bool customRenderLoop = false, MySandboxGame game = null )
        {
            MyLog.Default = MySandboxGame.Log;

            if (game == null)
            {
                Static = new MySandboxExternal(this, services, null, windowHandle);
            }
            else
            {
                Static = game;
            }

            Initialize(Static);

            

            //Sandbox.Definitions.MyDefinitionManager.Static.LoadData(new List<Sandbox.Common.ObjectBuilders.MyObjectBuilder_Checkpoint.ModItem>());

            //Static.In
            Static.OnGameLoaded += GameLoaded;
            Static.OnGameExit += GameExit;

            //GameLoaded(this, null);

            Static.Run(customRenderLoop);

            //LoadDefinitions();

            if (!customRenderLoop)
            {
                Dispose();
            }
        }
Ejemplo n.º 2
0
 public MySandboxExternal(IExternalApp externalApp, VRageGameServices services, string[] commandlineArgs, IntPtr windowHandle)
     : base(services, commandlineArgs)
 {
     WindowHandle = windowHandle;
     ExternalApp  = externalApp;
     m_control    = Control.FromHandle(windowHandle);
 }
Ejemplo n.º 3
0
 public MySandboxExternal(IExternalApp externalApp, VRageGameServices services, string[] commandlineArgs, IntPtr windowHandle)
     : base(services, commandlineArgs)
 {
     WindowHandle = windowHandle;
     ExternalApp = externalApp;
     m_control = Control.FromHandle(windowHandle);
 }
Ejemplo n.º 4
0
        //  Main method
        static void Main(string[] args)
        {
            SpaceEngineersGame.SetupBasicGameInfo();

            m_startup = new MyCommonProgramStartup(args);
            if (m_startup.PerformReporting()) return;
            m_startup.PerformAutoconnect();
            if (!m_startup.CheckSingleInstance()) return;
            var appDataPath = m_startup.GetAppDataPath();
            MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName, appDataPath);
            MyInitializer.InitCheckSum();
            m_startup.InitSplashScreen();
            if (!m_startup.Check64Bit()) return;

            m_startup.DetectSharpDxLeaksBeforeRun();
            using (MySteamService steamService = new MySteamService(MySandboxGame.IsDedicated, AppId))
            {
                m_renderer = null;
                SpaceEngineersGame.SetupPerGameSettings();
                SpaceEngineersGame.SetupRender();
                InitializeRender();

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyProgram.Init");

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MySteam.Init()");
                if (!m_startup.CheckSteamRunning(steamService)) return;
                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("new MySandboxGame()");

                VRageGameServices services = new VRageGameServices(steamService);

                if (!MySandboxGame.IsDedicated)
                    MyFileSystem.InitUserSpecific(steamService.UserId.ToString());

                using (SpaceEngineersGame game = new SpaceEngineersGame(services, args))
                {
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    game.Run(disposeSplashScreen: m_startup.DisposeSplashScreen);
                }
            }
            m_startup.DetectSharpDxLeaksAfterRun();

#if PROFILING
            MyPerformanceTimer.WriteToLog();
#endif
            MyInitializer.InvokeAfterRun();
        }
Ejemplo n.º 5
0
 public SpaceEngineersGame(VRageGameServices services, string[] commandlineArgs)
     : base(services, commandlineArgs)
 {
     MySandboxGame.GameCustomInitialization = new MySpaceGameCustomInitialization();
 }
Ejemplo n.º 6
0
        static void RunInternal(string[] args)
        {
            using (MySteamService steamService = new MySteamService(MySandboxGame.IsDedicated, AppId))
            {
                IMyRender renderer = null;

                if (MySandboxGame.IsDedicated)
                {
                    renderer = new MyNullRender();
                }
                else if (!MyFakes.ENABLE_DX11_RENDERER)
                {
                    renderer = new MyDX9Render();
                }
                else if (MyFakes.ENABLE_DX11_RENDERER)
                {
                    renderer = new MyDX11Render();
                }

                VRageRender.MyRenderProxy.Initialize(renderer);

                VRageRender.MyRenderProxy.IS_OFFICIAL = MyFinalBuildConstants.IS_OFFICIAL;
                VRageRender.MyRenderProxy.GetRenderProfiler().SetAutocommit(false);
                VRageRender.MyRenderProxy.GetRenderProfiler().InitMemoryHack("MainEntryPoint");
                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyProgram.Init");
                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MySteam.Init()");

                if (!MySandboxGame.IsDedicated)
                {
                    if (steamService.IsActive)
                    {
                        steamService.SetNotificationPosition(MySteamService.NotificationPosition.TopLeft);

                        MySandboxGame.Log.WriteLineAndConsole("Steam.IsActive: " + steamService.IsActive);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.IsOnline: " + steamService.IsOnline);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.OwnsGame: " + steamService.OwnsGame);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.UserId: " + steamService.UserId);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.UserName: "******"[n/a]");
                        MySandboxGame.Log.WriteLineAndConsole("Steam.Branch: " + steamService.BranchName ?? "[n/a]");
                        MySandboxGame.Log.WriteLineAndConsole("Build date: " + MySandboxGame.BuildDateTime.ToString("yyyy-MM-dd hh:mm", CultureInfo.InvariantCulture));
                        MySandboxGame.Log.WriteLineAndConsole("Build version: " + MySandboxGame.BuildVersion.ToString());
                    }
                    else if (MyFinalBuildConstants.IS_OFFICIAL) //We dont need Steam only in VS 
                    {
                        if (!(steamService.IsActive && steamService.OwnsGame))
                        {
                            MessageBoxWrapper("Steam is not running!", "Please run this game from Steam." + Environment.NewLine + "(restart Steam if already running)");
                            return;
                        }
                    }
                    else
                    {
                        if (!(steamService.IsActive && steamService.OwnsGame))
                        {
                            MessageBoxWrapper("Steam is not running!", "Game might be unstable when run without Steam!");
                        }
                    }
                }

                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("new MySandboxGame()");

                SpaceEngineersGame.SetupPerGameSettings();

                VRageGameServices services = new VRageGameServices(steamService);

                if (!MySandboxGame.IsDedicated)
                    MyFileSystem.InitUserSpecific(steamService.UserId.ToString());

                using (MySandboxGame game = new MySandboxGame(services, args))
                {
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    game.Run(disposeSplashScreen: DisposeSplashScreen);
                }
            }
        }
Ejemplo n.º 7
0
        public MySandboxGame(VRageGameServices services, string[] commandlineArgs)
        {
            ParseArgs(commandlineArgs);
            ProfilerShort.Begin("MySandboxGame()::constructor");
            MySandboxGame.Log.WriteLine("MySandboxGame.Constructor() - START");
            MySandboxGame.Log.IncreaseIndent();

            Services = services;

            SharpDX.Configuration.EnableObjectTracking = MyCompilationSymbols.EnableSharpDxObjectTracking;

            UpdateThread = Thread.CurrentThread;

            // we want check objectbuilders, prefab's configurations, gameplay constants and building specifications
            ProfilerShort.Begin("Checks");

            MySandboxGame.Log.WriteLine("Game dir: " + MyFileSystem.ExePath);
            MySandboxGame.Log.WriteLine("Content dir: " + MyFileSystem.ContentPath);

            ProfilerShort.BeginNextBlock("MyCustomGraphicsDeviceManagerDX");

            Static = this;

            Console.CancelKeyPress += Console_CancelKeyPress;

            ProfilerShort.BeginNextBlock("InitNumberOfCores");
            InitNumberOfCores();

            ProfilerShort.BeginNextBlock("MyTexts.Init()");
            MyLanguage.Init();

            MySession.OnReady += delegate
            {
                if (OnSessionReady != null)
                    OnSessionReady();
            };

            ProfilerShort.BeginNextBlock("MyDefinitionManager.LoadScenarios");
            MyDefinitionManager.Static.LoadScenarios();

            ProfilerShort.BeginNextBlock("Preallocate");
            Preallocate();

            if (!IsDedicated)
            {
                ProfilerShort.BeginNextBlock("new MyGameRenderComponent");
                GameRenderComponent = new MyGameRenderComponent();
            }
            else
            {
                ProfilerShort.BeginNextBlock("Dedicated server setup");
                MySandboxGame.ConfigDedicated.Load();
                //ignum
                //+connect 62.109.134.123:27025

                IPAddress address = MyDedicatedServerOverrides.IpAddress ?? IPAddressExtensions.ParseOrAny(MySandboxGame.ConfigDedicated.IP);
                ushort port = (ushort)(MyDedicatedServerOverrides.Port ?? MySandboxGame.ConfigDedicated.ServerPort);

                IPEndPoint ep = new IPEndPoint(address, port);

                MyLog.Default.WriteLineAndConsole("Bind IP : " + ep.ToString());

                MyDedicatedServer dedicatedServer = new MyDedicatedServer(ep);
                MyMultiplayer.Static = dedicatedServer;

                FatalErrorDuringInit = !dedicatedServer.ServerStarted;

                if (FatalErrorDuringInit && !Environment.UserInteractive)
                {
                    var e = new Exception("Fatal error during dedicated server init: " + dedicatedServer.ServerInitError);
                    e.Data["Silent"] = true;
                    throw e;
                }
            }

            // Game tags contain game data hash, so they need to be sent after preallocation
            if (IsDedicated && !FatalErrorDuringInit)
            {
                (MyMultiplayer.Static as MyDedicatedServer).SendGameTagsToSteam();
            }

            ProfilerShort.BeginNextBlock("InitMultithreading");

            InitMultithreading();

            ProfilerShort.End();

            if (!IsDedicated && SteamSDK.SteamAPI.Instance != null)
            {
                SteamSDK.SteamAPI.Instance.OnPingServerResponded += ServerResponded;
                SteamSDK.SteamAPI.Instance.OnPingServerFailedToRespond += ServerFailedToRespond;
                SteamSDK.Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed;
            }

            MyMessageLoop.AddMessageHandler(MyWMCodes.GAME_IS_RUNNING_REQUEST, OnToolIsGameRunningMessage);

            MySandboxGame.Log.DecreaseIndent();
            MySandboxGame.Log.WriteLine("MySandboxGame.Constructor() - END");
            ProfilerShort.End();
        }