protected override Texture2D GetTexture(Game game)
        {
            Texture2D      texture;
            GraphicsDevice gd            = game.RenderProcess.GraphicsDevice;
            string         defaultScreen = "load.ace";

            string loadingScreen = Simulator.Instance.TRK.Route.LoadingScreen;

            if (IsWideScreen(game))
            {
                string loadingScreenWide = Simulator.Instance.TRK.Route.LoadingScreenWide;
                loadingScreen = loadingScreenWide ?? loadingScreen;
            }
            loadingScreen = loadingScreen ?? defaultScreen;
            string path = Path.Combine(Simulator.Instance.RoutePath, loadingScreen);

            if (Path.GetExtension(path) == ".dds" && File.Exists(path))
            {
                DDSLib.DDSFromFile(path, gd, true, out texture);
            }
            else if (Path.GetExtension(path) == ".ace")
            {
                string alternativeTexture = Path.ChangeExtension(path, ".dds");

                if (File.Exists(alternativeTexture) && game.Settings.PreferDDSTexture)
                {
                    DDSLib.DDSFromFile(alternativeTexture, gd, true, out texture);
                }
                else if (File.Exists(path))
                {
                    texture = AceFile.Texture2DFromFile(gd, path);
                }
                else
                {
                    path = Path.Combine(Simulator.Instance.RoutePath, defaultScreen);
                    if (File.Exists(path))
                    {
                        texture = AceFile.Texture2DFromFile(gd, path);
                    }
                    else
                    {
                        texture = null;
                    }
                }
            }
            else
            {
                texture = null;
            }
            return(texture);
        }
Пример #2
0
        public GameModel(string meshPath, string texturePath = "null")
        {
            using (BinaryReader reader = new BinaryReader((Stream)File.OpenRead(meshPath)))
            {
                this.Header = Encoding.ASCII.GetString(reader.ReadBytes(16));
                C3PartType type = C3PartType.START;
                while (type != C3PartType.EXIT && reader.BaseStream.Position + 4L <= reader.BaseStream.Length)
                {
                    type = (C3PartType)reader.ReadInt32();
                    Console.WriteLine("Loading: " + (object)type);
                    switch (type)
                    {
                    case C3PartType.PHY4:
                    case C3PartType.PHY:
                    case C3PartType.PHY3:
                        this.PhysicalObjects.Add(Physics.ReadPhysics(reader, type));
                        break;

                    case C3PartType.MOTI:
                        this.Motions.Add(Motion.ReadMotion(reader));
                        break;

                    case C3PartType.SHAP:
                        this.Shapes.Add(Shape.ReadShape(reader));
                        break;

                    default:
                        reader.BaseStream.Position -= 4L;
                        int num = (int)MessageBox.Show("Warning: This file was not completely loaded. Please avoid exporting this model or it may become corrupted.");
                        type = C3PartType.EXIT;
                        break;
                    }
                }
                reader.Close();
            }
            meshPath = meshPath.Replace('\\', '/');
            int    num1 = meshPath.LastIndexOf('/');
            string s    = meshPath.Substring(num1 + 1, meshPath.Length - num1 - 4);

            int.TryParse(s, out this.ID);
            if (File.Exists(meshPath.Substring(0, meshPath.Length - 3) + ".dds"))
            {
                DDSLib.DDSFromFile(meshPath.Substring(0, meshPath.Length - 3) + ".dds", Settings.Graphics, false, out this.Texture);
            }
            else if (File.Exists(Settings.Conquer_Path + "c3/texture/" + s + ".dds"))
            {
                DDSLib.DDSFromFile(Settings.Conquer_Path + "c3/texture/" + s + ".dds", Settings.Graphics, false, out this.Texture);
            }
            else if (File.Exists(Settings.Conquer_Path + "c3/texture/" + (object)(this.ID / 10 * 10) + ".dds"))
            {
                DDSLib.DDSFromFile(Settings.Conquer_Path + "c3/texture/" + (object)(this.ID / 10 * 10) + ".dds", Settings.Graphics, false, out this.Texture);
            }
            this.Name = this.ID.ToString();
            foreach (Physics physicalObject in this.PhysicalObjects)
            {
                Settings.GUI.AddPhysicalObject(this.Name, physicalObject);
            }
            foreach (Shape shape in this.Shapes)
            {
                Settings.GUI.AddShape(this.Name, shape);
            }
        }
Пример #3
0
        protected override void Update(GameTime gameTime)
        {
            if (!this.IsActive || Settings.GUI.Visible)
            {
                this.mouseAim = false;
            }
            else
            {
                Vector3    zero   = Vector3.Zero;
                MouseState state1 = Mouse.GetState();
                if (!Settings.GUI.Visible && state1.LeftButton == ButtonState.Pressed && this.mouseState.LeftButton == ButtonState.Released)
                {
                    this.mouseState = Mouse.GetState();
                    if (this.showColorWheel && new Rectangle((int)this.colorWheelLocation.X, (int)this.colorWheelLocation.Y, this.colorWheel.Width, this.colorWheel.Height).Contains(new Point(this.mouseState.X, this.mouseState.Y)))
                    {
                        Color[] data = new Color[this.colorWheel.Width * this.colorWheel.Height];
                        this.colorWheel.GetData <Color>(data);
                        int index = this.mouseState.X + this.mouseState.Y * this.colorWheel.Width;
                        if (index < data.Length)
                        {
                            this.selectedColor = data[index];
                        }
                    }
                    else
                    {
                        this.mouseAim = !this.mouseAim;
                    }
                }
                if (this.mouseAim)
                {
                    this.camera.Yaw   -= (float)(state1.X - this.mouseState.X) * (1f / 500f);
                    this.camera.Pitch -= (float)(state1.Y - this.mouseState.Y) * (1f / 500f);
                    this.camera.Zoom  += (float)(this.mouseState.ScrollWheelValue - state1.ScrollWheelValue) * 0.05f;
                    Viewport viewport = this.GraphicsDevice.Viewport;
                    int      x        = viewport.Width / 2;
                    viewport = this.GraphicsDevice.Viewport;
                    int y = viewport.Height / 2;
                    Mouse.SetPosition(x, y);
                }
                this.mouseState = Mouse.GetState();
                KeyboardState state2 = Keyboard.GetState();
                foreach (Keys pressedKey in state2.GetPressedKeys())
                {
                    switch (pressedKey)
                    {
                    case Keys.S:
                    case Keys.End:
                    case Keys.Down:
                        this.camera.Pitch -= 0.025f;
                        break;

                    case Keys.W:
                    case Keys.Home:
                    case Keys.Up:
                        this.camera.Pitch += 0.025f;
                        break;

                    case Keys.LeftShift:
                        --this.camera.Zoom;
                        break;

                    case Keys.Space:
                        ++this.camera.Zoom;
                        break;

                    case Keys.PageDown:
                    case Keys.Right:
                    case Keys.D:
                        this.camera.Yaw -= 0.025f;
                        break;

                    case Keys.Left:
                    case Keys.Delete:
                    case Keys.A:
                        this.camera.Yaw += 0.025f;
                        break;
                    }
                }
                if (state2.IsKeyDown(Keys.Tab) && !this.keyboardState.IsKeyDown(Keys.Tab))
                {
                    this.CurrentRasterizeState = this.CurrentRasterizeState == this.WireframeRasterizeState ? this.FillRasterizeState : this.WireframeRasterizeState;
                }
                if (state2.IsKeyDown(Keys.F10) && !this.keyboardState.IsKeyDown(Keys.F10))
                {
                    int backBufferWidth  = this.GraphicsDevice.PresentationParameters.BackBufferWidth;
                    int backBufferHeight = this.GraphicsDevice.PresentationParameters.BackBufferHeight;
                    this.Draw(new GameTime());
                    int[] data = new int[backBufferWidth * backBufferHeight];
                    this.GraphicsDevice.GetBackBufferData <int>(data);
                    Texture2D texture2D = new Texture2D(this.GraphicsDevice, backBufferWidth, backBufferHeight, false, this.GraphicsDevice.PresentationParameters.BackBufferFormat);
                    texture2D.SetData <int>(data);
                    Stream stream = (Stream)File.OpenWrite("Screenshots/" + (object)Environment.TickCount + ".jpg");
                    texture2D.SaveAsJpeg(stream, backBufferWidth, backBufferHeight);
                    stream.Dispose();
                    texture2D.Dispose();
                }
                if (state2.IsKeyDown(Keys.F1) && !this.keyboardState.IsKeyDown(Keys.F1))
                {
                    Settings.GUI.Show();
                }
                if (state2.IsKeyDown(Keys.F5) && !this.keyboardState.IsKeyDown(Keys.F5))
                {
                    System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
                    string str = (Settings.Conquer_Path + "c3/weapon/").Replace('/', '\\');
                    openFileDialog.InitialDirectory = str;
                    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        Settings.Scene.LoadModel(openFileDialog.FileName);
                        this.centerCamera();
                    }
                }
                if (state2.IsKeyDown(Keys.F2) && !this.keyboardState.IsKeyDown(Keys.F2))
                {
                    System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
                    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        Settings.Scene.LoadModel(openFileDialog.FileName);
                        this.centerCamera();
                    }
                }
                if (state2.IsKeyDown(Keys.F3) && !this.keyboardState.IsKeyDown(Keys.F3))
                {
                    System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
                    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (Settings.GUI.SelectedModel == null)
                        {
                            Settings.GUI.SelectedModel = Settings.Scene.Models.FirstOrDefault <GameModel>();
                        }
                        if (Settings.GUI.SelectedModel != null)
                        {
                            DDSLib.DDSFromFile(openFileDialog.FileName, this.GraphicsDevice, false, out Settings.GUI.SelectedModel.Texture);
                        }
                    }
                }
                if (state2.IsKeyDown(Keys.F12) && !this.keyboardState.IsKeyDown(Keys.F12))
                {
                    Settings.Scene = new GameScene();
                    Settings.GUI   = new Manager();
                }
                foreach (GameModel model in Settings.Scene.Models)
                {
                    foreach (Physics physicalObject in model.PhysicalObjects)
                    {
                        if (physicalObject.Motion != null && DateTime.Now > this.nextFrame)
                        {
                            this.nextFrame            = DateTime.Now.AddMilliseconds(30.0);
                            physicalObject.FrameIndex = (physicalObject.FrameIndex + 1) % physicalObject.Motion.KeyFrames.Count;
                        }
                        if (!(physicalObject.UV_Step == Vector2.Zero))
                        {
                            foreach (Vertex normalVertex in physicalObject.NormalVertexes)
                            {
                                normalVertex.UV += physicalObject.UV_Step;
                            }
                            foreach (Vertex alphaVertex in physicalObject.AlphaVertexes)
                            {
                                alphaVertex.UV += physicalObject.UV_Step;
                            }
                        }
                    }
                }
                this.keyboardState = state2;
                base.Update(gameTime);
            }
        }