Ejemplo n.º 1
0
 private static void _CloseProgram()
 {
     // Unloading in reverse order
     try
     {
         CController.Close();
         CVocaluxeServer.Close();
         CGraphics.Close();
         CThemes.Close();
         CCover.Close();
         CFonts.Close();
         CBackgroundMusic.Close();
         CWebcam.Close();
         CDataBase.Close();
         CVideo.Close();
         CRecord.Close();
         CSound.Close();
         CDraw.Close();
     }
     catch (Exception e)
     {
         CLog.LogError("Error during shutdown!", false, false, e);
     }
     GC.Collect(); // Do a GC run here before we close logs to have finalizers run
     try
     {
         CLog.Close(); // Do this last, so we get all log entries!
     }
     catch (Exception) {}
     Environment.Exit(Environment.ExitCode);
 }
Ejemplo n.º 2
0
        private void _GenerateQRs()
        {
            QRCodeGenerator qr = new QRCodeGenerator();

            //ServerAddress
            QRCodeGenerator.QRCode qrcode = qr.CreateQrCode(CVocaluxeServer.GetServerAddress(), QRCodeGenerator.ECCLevel.H);
            _QRServerAddress = CDraw.AddTexture(qrcode.GetGraphic(20));
        }
Ejemplo n.º 3
0
 private bool _UpdateBackground()
 {
     string[] photos = CVocaluxeServer.GetPhotosOfThisRound();
     _SlideShowBG.RemoveSlideShowTextures();
     foreach (string photo in photos)
     {
         _SlideShowBG.AddSlideShowTexture(photo);
     }
     return(photos.Length > 0);
 }
Ejemplo n.º 4
0
 public override void OnShow()
 {
     base.OnShow();
     if (_QRServerAddress == null)
     {
         _GenerateQRs();
         _Statics[_StaticQRServer].Texture = _QRServerAddress;
         _Texts[_TextServerAddress].Text   = CVocaluxeServer.GetServerAddress();
     }
     _Texts[_TextServerAddress].Visible    = CVocaluxeServer.IsServerRunning();
     _Statics[_StaticQRServer].Visible     = CVocaluxeServer.IsServerRunning();
     _Texts[_TextServerNotRunning].Visible = !CVocaluxeServer.IsServerRunning();
 }
Ejemplo n.º 5
0
        private static void _Run(string[] args)
        {
            Application.DoEvents();

            try
            {
                // Create data folder
                Directory.CreateDirectory(CSettings.DataFolder);

                // Init Log
                CLog.Init();

                if (!CProgrammHelper.CheckRequirements())
                {
                    return;
                }
                CProgrammHelper.Init();

                CLog.StartBenchmark("Init Program");
                CMain.Init();
                Application.DoEvents();

                // Init Language
                CLog.StartBenchmark("Init Language");
                if (!CLanguage.Init())
                {
                    throw new CLoadingException("Language");
                }
                CLog.StopBenchmark("Init Language");

                Application.DoEvents();

                // load config
                CLog.StartBenchmark("Init Config");
                CConfig.LoadCommandLineParams(args);
                CConfig.UseCommandLineParamsBefore();
                CConfig.Init();
                CConfig.UseCommandLineParamsAfter();
                CLog.StopBenchmark("Init Config");

                // Create folders
                CSettings.CreateFolders();

                _SplashScreen = new CSplashScreen();
                Application.DoEvents();

                // Init Draw
                CLog.StartBenchmark("Init Draw");
                if (!CDraw.Init())
                {
                    throw new CLoadingException("drawing");
                }
                CLog.StopBenchmark("Init Draw");

                Application.DoEvents();

                // Init Playback
                CLog.StartBenchmark("Init Playback");
                if (!CSound.Init())
                {
                    throw new CLoadingException("playback");
                }
                CLog.StopBenchmark("Init Playback");

                Application.DoEvents();

                // Init Record
                CLog.StartBenchmark("Init Record");
                if (!CRecord.Init())
                {
                    throw new CLoadingException("record");
                }
                CLog.StopBenchmark("Init Record");

                Application.DoEvents();

                // Init VideoDecoder
                CLog.StartBenchmark("Init Videodecoder");
                if (!CVideo.Init())
                {
                    throw new CLoadingException("video");
                }
                CLog.StopBenchmark("Init Videodecoder");

                Application.DoEvents();

                // Init Database
                CLog.StartBenchmark("Init Database");
                if (!CDataBase.Init())
                {
                    throw new CLoadingException("database");
                }
                CLog.StopBenchmark("Init Database");

                Application.DoEvents();

                //Init Webcam
                CLog.StartBenchmark("Init Webcam");
                if (!CWebcam.Init())
                {
                    throw new CLoadingException("webcam");
                }
                CLog.StopBenchmark("Init Webcam");

                Application.DoEvents();

                // Init Background Music
                CLog.StartBenchmark("Init Background Music");
                CBackgroundMusic.Init();
                CLog.StopBenchmark("Init Background Music");

                Application.DoEvents();

                // Init Profiles
                CLog.StartBenchmark("Init Profiles");
                CProfiles.Init();
                CLog.StopBenchmark("Init Profiles");

                Application.DoEvents();

                // Init Fonts
                CLog.StartBenchmark("Init Fonts");
                if (!CFonts.Init())
                {
                    throw new CLoadingException("fonts");
                }
                CLog.StopBenchmark("Init Fonts");

                Application.DoEvents();

                // Theme System
                CLog.StartBenchmark("Init Theme");
                if (!CThemes.Init())
                {
                    throw new CLoadingException("theme");
                }
                CLog.StopBenchmark("Init Theme");

                CLog.StartBenchmark("Load Theme");
                CThemes.Load();
                CLog.StopBenchmark("Load Theme");

                Application.DoEvents();

                // Load Cover
                CLog.StartBenchmark("Init Cover");
                if (!CCover.Init())
                {
                    throw new CLoadingException("covertheme");
                }
                CLog.StopBenchmark("Init Cover");

                Application.DoEvents();

                // Init Screens
                CLog.StartBenchmark("Init Screens");
                CGraphics.Init();
                CLog.StopBenchmark("Init Screens");

                Application.DoEvents();

                // Init Server
                CLog.StartBenchmark("Init Server");
                CVocaluxeServer.Init();
                CLog.StopBenchmark("Init Server");

                Application.DoEvents();

                // Init Input
                CLog.StartBenchmark("Init Input");
                CController.Init();
                CController.Connect();
                CLog.StopBenchmark("Init Input");

                Application.DoEvents();

                // Init Game;
                CLog.StartBenchmark("Init Game");
                CGame.Init();
                CProfiles.Update();
                CConfig.UsePlayers();
                CLog.StopBenchmark("Init Game");

                Application.DoEvents();

                // Init Party Modes;
                CLog.StartBenchmark("Init Party Modes");
                if (!CParty.Init())
                {
                    throw new CLoadingException("Party Modes");
                }
                CLog.StopBenchmark("Init Party Modes");

                Application.DoEvents();
                //Only reasonable point to call GC.Collect() because initialization may cause lots of garbage
                //Rely on GC doing its job afterwards and call Dispose methods where appropriate
                GC.Collect();
                CLog.StopBenchmark("Init Program");
            }
            catch (Exception e)
            {
                MessageBox.Show("Error on start up: " + e.Message);
                CLog.LogError("Error on start up: " + e);
                if (_SplashScreen != null)
                {
                    _SplashScreen.Close();
                }
                _CloseProgram();
                return;
            }
            Application.DoEvents();

            // Start Main Loop
            if (_SplashScreen != null)
            {
                _SplashScreen.Close();
            }

            CDraw.MainLoop();
        }
Ejemplo n.º 6
0
        private static void _Run(string[] args)
        {
            Application.DoEvents();

            try
            {
                // Create data folder
                Directory.CreateDirectory(CSettings.DataFolder);

                // Init Log
                CLog.Init(CSettings.FolderNameLogs,
                          CSettings.FileNameMainLog,
                          CSettings.FileNameSongLog,
                          CSettings.FileNameCrashMarker,
                          CSettings.GetFullVersionText(),
                          CReporter.ShowReporterFunc,
                          ELogLevel.Information);

                if (!CProgrammHelper.CheckRequirements())
                {
                    return;
                }
                CProgrammHelper.Init();

                using (CBenchmark.Time("Init Program"))
                {
                    CMain.Init();
                    Application.DoEvents();

                    // Init Language
                    using (CBenchmark.Time("Init Language"))
                    {
                        if (!CLanguage.Init())
                        {
                            throw new CLoadingException("Language");
                        }
                    }

                    Application.DoEvents();

                    // load config
                    using (CBenchmark.Time("Init Config"))
                    {
                        CConfig.LoadCommandLineParams(args);
                        CConfig.UseCommandLineParamsBefore();
                        CConfig.Init();
                        CConfig.UseCommandLineParamsAfter();
                    }

                    // Create folders
                    CSettings.CreateFolders();

                    _SplashScreen = new CSplashScreen();
                    Application.DoEvents();

                    // Init Draw
                    using (CBenchmark.Time("Init Draw"))
                    {
                        if (!CDraw.Init())
                        {
                            throw new CLoadingException("drawing");
                        }
                    }

                    Application.DoEvents();

                    // Init Playback
                    using (CBenchmark.Time("Init Playback"))
                    {
                        if (!CSound.Init())
                        {
                            throw new CLoadingException("playback");
                        }
                    }

                    Application.DoEvents();

                    // Init Record
                    using (CBenchmark.Time("Init Record"))
                    {
                        if (!CRecord.Init())
                        {
                            throw new CLoadingException("record");
                        }
                    }

                    Application.DoEvents();

                    // Init VideoDecoder
                    using (CBenchmark.Time("Init Videodecoder"))
                    {
                        if (!CVideo.Init())
                        {
                            throw new CLoadingException("video");
                        }
                    }

                    Application.DoEvents();

                    // Init Database
                    using (CBenchmark.Time("Init Database"))
                    {
                        if (!CDataBase.Init())
                        {
                            throw new CLoadingException("database");
                        }
                    }

                    Application.DoEvents();

                    //Init Webcam
                    using (CBenchmark.Time("Init Webcam"))
                    {
                        if (!CWebcam.Init())
                        {
                            throw new CLoadingException("webcam");
                        }
                    }

                    Application.DoEvents();

                    // Init Background Music
                    using (CBenchmark.Time("Init Background Music"))
                    {
                        CBackgroundMusic.Init();
                    }

                    Application.DoEvents();

                    // Init Profiles
                    using (CBenchmark.Time("Init Profiles"))
                    {
                        CProfiles.Init();
                    }

                    Application.DoEvents();

                    // Init Fonts
                    using (CBenchmark.Time("Init Fonts"))
                    {
                        if (!CFonts.Init())
                        {
                            throw new CLoadingException("fonts");
                        }
                    }

                    Application.DoEvents();

                    // Theme System
                    using (CBenchmark.Time("Init Theme"))
                    {
                        if (!CThemes.Init())
                        {
                            throw new CLoadingException("theme");
                        }
                    }

                    using (CBenchmark.Time("Load Theme"))
                    {
                        CThemes.Load();
                    }

                    Application.DoEvents();

                    // Load Cover
                    using (CBenchmark.Time("Init Cover"))
                    {
                        if (!CCover.Init())
                        {
                            throw new CLoadingException("covertheme");
                        }
                    }

                    Application.DoEvents();

                    // Init Screens
                    using (CBenchmark.Time("Init Screens"))
                    {
                        CGraphics.Init();
                    }

                    Application.DoEvents();

                    // Init Server
                    using (CBenchmark.Time("Init Server"))
                    {
                        CVocaluxeServer.Init();
                    }

                    Application.DoEvents();

                    // Init Input
                    using (CBenchmark.Time("Init Input"))
                    {
                        CController.Init();
                        CController.Connect();
                    }

                    Application.DoEvents();

                    // Init Game
                    using (CBenchmark.Time("Init Game"))
                    {
                        CGame.Init();
                        CProfiles.Update();
                        CConfig.UsePlayers();
                    }

                    Application.DoEvents();

                    // Init Party Modes
                    using (CBenchmark.Time("Init Party Modes"))
                    {
                        if (!CParty.Init())
                        {
                            throw new CLoadingException("Party Modes");
                        }
                    }

                    Application.DoEvents();
                    //Only reasonable point to call GC.Collect() because initialization may cause lots of garbage
                    //Rely on GC doing its job afterwards and call Dispose methods where appropriate
                    GC.Collect();
                }
            }
            catch (Exception e)
            {
                CLog.Error(e, "Error on start up: {ExceptionMessage}", CLog.Params(e.Message), show: true);
                if (_SplashScreen != null)
                {
                    _SplashScreen.Close();
                }
                _CloseProgram();
                return;
            }
            Application.DoEvents();

            // Start Main Loop
            if (_SplashScreen != null)
            {
                _SplashScreen.Close();
            }

            CDraw.MainLoop();
        }
Ejemplo n.º 7
0
        // Resharper doesn't get that this is used -.-
        // ReSharper disable UnusedMemberHiearchy.Global
        /// <summary>
        ///     Starts the rendering
        /// </summary>
        public virtual void MainLoop()
        {
            // ReSharper restore UnusedMemberHiearchy.Global
            _EnsureMainThread();
            _Run = true;

            _Fullscreen = false;
            if (CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON)
            {
                _EnterFullScreen();
            }
            else
            {
                _DoResize(); //Resize window if aspect ratio is incorrect
            }
            while (_Run)
            {
                _CheckQueue();
                CVocaluxeServer.ProcessServerTasks();

                //We want to begin drawing
                _OnBeforeDraw();

                //Clear the previous Frame
                _ClearScreen();
                if (!CGraphics.Draw())
                {
                    _Run = false;
                }
                _OnAfterDraw();

                if (!CGraphics.UpdateGameLogic(_Keys, _Mouse))
                {
                    _Run = false;
                }

                //Apply fullscreen mode
                if ((CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON) != _Fullscreen)
                {
                    _ToggleFullScreen();
                }

                //Apply border changes
                if (_BorderLeft != CConfig.Config.Graphics.BorderLeft || _BorderRight != CConfig.Config.Graphics.BorderRight || _BorderTop != CConfig.Config.Graphics.BorderTop ||
                    _BorderBottom != CConfig.Config.Graphics.BorderBottom)
                {
                    _BorderLeft   = CConfig.Config.Graphics.BorderLeft;
                    _BorderRight  = CConfig.Config.Graphics.BorderRight;
                    _BorderTop    = CConfig.Config.Graphics.BorderTop;
                    _BorderBottom = CConfig.Config.Graphics.BorderBottom;

                    _AdjustNewBorders();
                }

                if (_CurrentAlignment != CConfig.Config.Graphics.ScreenAlignment)
                {
                    _DoResize();
                }

                if (CConfig.Config.Graphics.VSync == EOffOn.TR_CONFIG_OFF)
                {
                    if (CTime.IsRunning())
                    {
                        int delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds());

                        if (delay >= 1 && delay < 500)
                        {
                            Thread.Sleep(delay);
                        }
                    }
                }
                //Calculate the FPS Rate and restart the timer after a frame
                CTime.CalculateFPS();
                CTime.Restart();
            }
        }