Exemplo n.º 1
0
 private static void Main()
 {
     try
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         using (ShanghaiEXE form = new ShanghaiEXE())
         {
             Loading loading = new Loading(form);
             loading.Show();
             new Thread(new ThreadStart(loading.MainLoop)).Start();
             form.loading = loading;
             form.InitializeData();
             while (form.Created || loading.Created)
             {
                 form.MainLoop();
             }
         }
     }
     catch (Exception e) when(!System.Diagnostics.Debugger.IsAttached)
     {
         if (Application.OpenForms.Count > 0)
         {
             var messageText = e.ToString();
             MessageBox.Show(messageText, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         Environment.Exit(1);
     }
 }
Exemplo n.º 2
0
        private static void LoadKeyItems()
        {
            var languageDoc = new XmlDocument();

            languageDoc.Load($"data/data/KeyItems.xml");

            var keyItemNodes = languageDoc.SelectNodes("data/KeyItem");

            foreach (XmlNode keyItemNode in keyItemNodes)
            {
                var index = int.Parse(keyItemNode?.Attributes["Index"]?.Value ?? "-1");

                if (index == -1)
                {
                    throw new InvalidOperationException("Invalid Key Item index.");
                }

                var name = ShanghaiEXE.Translate(keyItemNode?.Attributes["Name"].Value);

                var info      = new List <string>();
                var dialogues = keyItemNode.ChildNodes;
                foreach (XmlNode dialogueXml in dialogues)
                {
                    var dialogue = ShanghaiEXE.Translate(dialogueXml.Attributes["Key"].Value);
                    info.Add(dialogue[0]);
                    info.Add(dialogue[1]);
                    info.Add(dialogue[2]);
                }

                KeyItems[index] = new KeyItem(name, info);
            }
        }
Exemplo n.º 3
0
        private static void LoadMail()
        {
            var languageDoc = new XmlDocument();

            languageDoc.Load($"data/data/Mail.xml");

            var mailNodes = languageDoc.SelectNodes("data/Mail");

            foreach (XmlNode mailNode in mailNodes)
            {
                var index = int.Parse(mailNode?.Attributes["Index"]?.Value ?? "-1");

                if (index == -1)
                {
                    throw new InvalidOperationException("Invalid Key Item index.");
                }

                var subject = ShanghaiEXE.Translate(mailNode?.Attributes["Subject"].Value);
                var sender  = ShanghaiEXE.Translate(mailNode?.Attributes["Sender"].Value);

                var dialogues = new List <Dialogue>();

                var info          = new List <string>();
                var dialogueNodes = mailNode.ChildNodes;
                foreach (XmlNode dialogueXml in dialogueNodes)
                {
                    dialogues.Add(ShanghaiEXE.Translate(dialogueXml.Attributes["Key"].Value));
                }

                Mail[index] = new MailItem(subject, sender, dialogues);
            }
        }
Exemplo n.º 4
0
 private void Init()
 {
     this.loadSUCCESS  = this.savedata.loadSucces;
     ShanghaiEXE.scene = new FirstTitle(this.ad, this, this.savedata);
     ShanghaiEXE.scene.Init();
     this.init = true;
     this.Text = ShanghaiEXE.Translate("Common.Title").Text;
 }
Exemplo n.º 5
0
 private void Game_Load(object sender, EventArgs e)
 {
     this.ClientSize = new Size(640, 480);
     if (!ShanghaiEXE.Config.Fullscreen)
     {
         this.Text = ShanghaiEXE.Translate("Common.Title");
     }
     this.Top  = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
     this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
 }
Exemplo n.º 6
0
 public SceneMain(IAudioEngine s, ShanghaiEXE p, SaveData save)
     : base(s, p, save)
 {
     this.eventmanager = new EventManager(this.mapscene, this.sound);
     for (int index1 = 0; index1 < this.chipfolder.GetLength(0); ++index1)
     {
         for (int index2 = 0; index2 < this.chipfolder.GetLength(1); ++index2)
         {
             this.chipfolder[index1, index2] = new ChipFolder(this.sound);
             this.chipfolder[index1, index2].SettingChip(this.savedata.chipFolder[index1, index2, 0]);
             this.chipfolder[index1, index2].codeNo = this.savedata.chipFolder[index1, index2, 1];
         }
     }
     this.parent      = p;
     this.battlescene = new SceneBattle(this.sound, p, this, this.eventmanager, true, 0, true, "", this.savedata);
     this.mapscene    = new SceneMap(this.sound, p, this, this.eventmanager, save);
     this.nowscene    = SceneMain.PLAYSCENE.map;
 }
Exemplo n.º 7
0
        public void LoadGame()
        {
            SceneMain scene = (SceneMain)ShanghaiEXE.scene;

            var retconMessages = this.savedata.RetconSave();

            if (retconMessages.Any())
            {
                scene.mapscene.eventmanager.AddEvent(new Fade(this.ad, scene.mapscene.eventmanager, 5, 255, 0, 0, 0, true, this.savedata));
                scene.mapscene.eventmanager.AddEvent(new OpenMassageWindow(this.ad, scene.mapscene.eventmanager));
                var retconListQuestion = ShanghaiEXE.Translate("Retcon.OpeningMessageQuestion");
                var retconListOptions  = ShanghaiEXE.Translate("Retcon.OpeningMessageQuestionOptions");
                scene.mapscene.eventmanager.AddEvent(new Question(
                                                         this.ad,
                                                         scene.mapscene.eventmanager,
                                                         retconListQuestion[0],
                                                         retconListQuestion[1],
                                                         retconListOptions[0],
                                                         retconListOptions[1],
                                                         retconListQuestion.Face.Mono,
                                                         true,
                                                         retconListQuestion.Face,
                                                         this.savedata,
                                                         true));
                scene.mapscene.eventmanager.AddEvent(new BranchHead(this.ad, scene.mapscene.eventmanager, 0, this.savedata));
                scene.mapscene.eventmanager.AddEvent(new CanSkip(this.ad, scene.mapscene.eventmanager, this.savedata));
                foreach (var message in retconMessages)
                {
                    scene.mapscene.eventmanager.AddEvent(new CommandMessage(this.ad, scene.mapscene.eventmanager, message[0], message[1], message[2], message.Face, message.Face.Mono, this.savedata));
                }
                scene.mapscene.eventmanager.AddEvent(new BranchEnd(this.ad, scene.mapscene.eventmanager, this.savedata));
                scene.mapscene.eventmanager.AddEvent(new CloseMassageWindow(this.ad, scene.mapscene.eventmanager));
                scene.mapscene.eventmanager.AddEvent(new StopSkip(this.ad, scene.mapscene.eventmanager, this.savedata));
                scene.mapscene.eventmanager.AddEvent(new Fade(this.ad, scene.mapscene.eventmanager, 15, 0, 0, 0, 0, true, this.savedata));
            }

            scene.mapscene.LoadGame();
            ShanghaiEXE.scene = scene;
        }
Exemplo n.º 8
0
        public void MainLoop()
        {
            var desiredUpdateRate = UpdateRate;
            var isTurbo           = Input.IsPush(Button.Turbo);

            if (isTurbo)
            {
                desiredUpdateRate = (ShanghaiEXE.Config.AllowTurboSlowdown ?? false)
                    ? ShanghaiEXE.Config.TurboUPS.Value
                    : Math.Max(60, ShanghaiEXE.Config.TurboUPS ?? 300);
            }
            var fpsAdjustment = isTurbo || Math.Abs(this.fpsAdjustmentFactor) < double.Epsilon || double.IsNaN(this.fpsAdjustmentFactor) || double.IsInfinity(this.fpsAdjustmentFactor) ? 1 : this.fpsAdjustmentFactor;
            var updatePeriod  = TimeSpan.FromMilliseconds(1000d / (desiredUpdateRate * fpsAdjustment));
            var renderPeriod  = TimeSpan.FromMilliseconds(1000d / ShanghaiEXE.Config.FPS ?? 60);

            var isUpdatePaused = this.isPaused && ShanghaiEXE.Config.PausedWhenInactive;

            var queuedUpdates = 0;

            if (updatePeriod > TimeSpan.Zero)
            {
                queuedUpdates = (int)(this.updateStopwatch.ElapsedMilliseconds / updatePeriod.TotalMilliseconds);
            }
            else
            {
                // If DirectX9, dg.End() blocks execution and queuedUpdates = 1 caps speed to refresh rate
                // "Incorrect" behavior if OpenGL or when FPS set to 144 on a 60hz screen, but this is edge case anyways with essentially infinite speed
                // TODO: split render to separate thread, if safe and no race conditions from render changing things (unlikely)
                queuedUpdates = (int)(renderPeriod.TotalSeconds / (1d / desiredUpdateRate));
            }

            var isUpdating = queuedUpdates > 0;

            if (isUpdating)
            {
                this.updateStopwatch.Restart();
            }
            var isRendering = this.renderStopwatch.Elapsed >= renderPeriod;

            if (isRendering)
            {
                this.renderStopwatch.Restart();
                this.rendersSinceLastFPSUpdate++;
            }

            if (isUpdating || isRendering)
            {
                if (this.init && (this.soundLoad && this.textureLoad))
                {
                    this.Show();
                    this.loading.Dispose();
                    this.init    = false;
                    this.loadend = true;
                    this.dg.AbortRenderThread();
                }
                if (this.loadend)
                {
                    if (isUpdating)
                    {
                        this.GetKeyData();
                    }

                    if (ShanghaiEXE.scene != null)
                    {
                        if (!isUpdatePaused)
                        {
                            for (var i = 0; i < queuedUpdates; i++)
                            {
                                if (i > 0)
                                {
                                    this.GetKeyData();
                                }
                                ShanghaiEXE.scene.Updata();

                                this.updatesSinceLastFPSUpdate++;
                                this.updatesSinceLastFPSAdjustment++;
                            }
                        }

                        ShanghaiEXE.rend = isRendering;
                        if (ShanghaiEXE.rend)
                        {
                            this.dg.Begin(Color.Black);
                            ShanghaiEXE.scene.Render(this.dg);
                            this.dg.End();
                        }

                        if (this.ad.MusicPlay)
                        {
                            this.ad.PlayingMusic();
                            this.ad.BGMFade();
                        }
                    }
                }
                else
                {
                    this.loading.MainLoop();
                }
                Application.DoEvents();
            }

            var timeSinceLastFPSAdjustment = this.fpsAdjustmentStopwatch.Elapsed;

            if (!isUpdatePaused && timeSinceLastFPSAdjustment > ShanghaiEXE.FPSAdjustmentPeriod)
            {
                if (this.loadend)
                {
                    var expectedUpdatesSinceLastAdjustment = ShanghaiEXE.FPSAdjustmentPeriod.TotalMilliseconds / updatePeriod.TotalMilliseconds;
                    var newFpsAdjustment = expectedUpdatesSinceLastAdjustment / this.updatesSinceLastFPSAdjustment;
                    this.fpsAdjustmentFactor = (newFpsAdjustment + (fpsAdjustment * (ShanghaiEXE.FPSAdjustmentWindow - 1))) / ShanghaiEXE.FPSAdjustmentWindow;
                }
                this.updatesSinceLastFPSAdjustment = 0;
                this.fpsAdjustmentStopwatch.Restart();
            }
            if (isUpdatePaused || isTurbo)
            {
                this.fpsAdjustmentStopwatch.Restart();
                this.updatesSinceLastFPSAdjustment = 0;
            }

            var timeSinceLastFPSUpdate = this.fpsUpdateStopwatch.Elapsed;

            if (timeSinceLastFPSUpdate > ShanghaiEXE.FPSUpdatePeriod)
            {
                if (this.updatesSinceLastFPSUpdate != 0)
                {
                    var title     = ShanghaiEXE.Translate("Common.Title").Text;
                    var fpsString = $"  FPS {this.rendersSinceLastFPSUpdate / timeSinceLastFPSUpdate.TotalSeconds:0.##} ({this.updatesSinceLastFPSUpdate / timeSinceLastFPSUpdate.TotalSeconds:0.##})";
                    if (!ShanghaiEXE.Config.Fullscreen)
                    {
                        this.Text = title + fpsString;
                    }
                }

                this.fpsUpdateStopwatch.Restart();
                this.rendersSinceLastFPSUpdate = 0;
                this.updatesSinceLastFPSUpdate = 0;
            }

            if (!this.loadend || !isTurbo)
            {
                Thread.Sleep(1);
            }
        }
Exemplo n.º 9
0
 protected SceneBase(IAudioEngine s, ShanghaiEXE p, SaveData save)
     : base(s)
 {
     this.parent   = p;
     this.savedata = save;
 }
Exemplo n.º 10
0
        private void InitializeComponent()
        {
            this.loadingBar = new ProgressBar();
            var tableLayout = new TableLayoutPanel {
                ColumnCount = 5, RowCount = 1
            };

            tableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20f));
            tableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20f));
            tableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20f));
            tableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20f));
            tableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20f));
            this.splashPicture = new PictureBox();
            this.loadingText[LoadType.Data] = new Label {
                Text = ShanghaiEXE.Translate("Startup.LoadGameData"), Width = 80, TextAlign = ContentAlignment.MiddleCenter, Anchor = AnchorStyles.None
            };
            this.loadingText[LoadType.Device] = new Label {
                Text = ShanghaiEXE.Translate("Startup.LoadDevice"), Width = 80, TextAlign = ContentAlignment.MiddleCenter, Anchor = AnchorStyles.None
            };
            this.loadingText[LoadType.Save] = new Label {
                Text = ShanghaiEXE.Translate("Startup.LoadSave"), Width = 80, TextAlign = ContentAlignment.MiddleCenter, Anchor = AnchorStyles.None
            };
            this.loadingText[LoadType.Audio] = new Label {
                Text = ShanghaiEXE.Translate("Startup.LoadAudio"), Width = 80, TextAlign = ContentAlignment.MiddleCenter, Anchor = AnchorStyles.None
            };
            this.loadingText[LoadType.Graphics] = new Label {
                Text = ShanghaiEXE.Translate("Startup.LoadGraphics"), Width = 80, TextAlign = ContentAlignment.MiddleCenter, Anchor = AnchorStyles.None
            };
            ((ISupportInitialize)this.splashPicture).BeginInit();
            this.SuspendLayout();
            this.loadingBar.Location = new Point(12, 390);
            this.loadingBar.Maximum  = 100;
            this.loadingBar.Name     = "_LoadBer";
            this.loadingBar.Size     = new Size(480, 23);
            this.loadingBar.TabIndex = 0;
            tableLayout.Location     = new Point(12, 360);
            tableLayout.Size         = new Size(480, 23);
            tableLayout.Controls.Add(this.loadingText[LoadType.Data], 0, 0);
            tableLayout.Controls.Add(this.loadingText[LoadType.Device], 1, 0);
            tableLayout.Controls.Add(this.loadingText[LoadType.Save], 2, 0);
            tableLayout.Controls.Add(this.loadingText[LoadType.Audio], 3, 0);
            tableLayout.Controls.Add(this.loadingText[LoadType.Graphics], 4, 0);
            var    assembly     = Assembly.GetExecutingAssembly();
            string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith($"load02.jpg", StringComparison.InvariantCultureIgnoreCase));

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                this.splashPicture.Image = Bitmap.FromStream(stream);
            }
            this.splashPicture.InitialImage = null;
            this.splashPicture.Location     = new Point(12, 12);
            this.splashPicture.Name         = "pictureBox1";
            this.splashPicture.Size         = new Size(480, 360);
            this.splashPicture.TabIndex     = 2;
            this.splashPicture.TabStop      = false;
            this.Controls.Add(loadingBar);
            this.Controls.Add(tableLayout);
            this.Controls.Add(splashPicture);
            this.AutoScaleDimensions = new SizeF(6f, 12f);
            this.AutoScaleMode       = AutoScaleMode.Font;
            this.ClientSize          = new Size(507, 423);
            this.ControlBox          = false;
            this.FormBorderStyle     = FormBorderStyle.None;
            this.MaximizeBox         = false;
            this.MinimizeBox         = false;
            this.Name          = nameof(Loading);
            this.ShowIcon      = false;
            this.ShowInTaskbar = false;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Text          = nameof(Loading);
            ((ISupportInitialize)this.splashPicture).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
        }