protected override void Initialize() { graphics.GraphicsProfile = GraphicsProfile.HiDef; UpdateAntiAlias(); UpdateVSync(); graphics.ApplyChanges(); IsMouseVisible = false; spriteBatch = new SpriteBatch(GraphicsDevice); camera = new FirstPersonCamera(this); rightCamera = new FirstPersonCamera(this); leftCamera = new FirstPersonCamera(this); skycamera = new FirstPersonCamera(this); UpdateEffects(); for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++) { GamePadState state = GamePad.GetState(i); if (state.IsConnected) { activeGamePad = i; break; } } Samplers.Refresh(); Samplers.InitRasterizers(); SwitchDisplayMode(); base.Initialize(); }
protected override void Initialize() { graphics.PreferMultiSampling = true; graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.SynchronizeWithVerticalRetrace = true; IsFixedTimeStep = true; graphics.ApplyChanges(); graphics.GraphicsDevice.PresentationParameters.MultiSampleCount = 4; Samplers.Refresh(); GoWindowed(); IsMouseVisible = false; effect = new BasicEffect(graphics.GraphicsDevice); effect.VertexColorEnabled = true; effect.TextureEnabled = true; effect.DiffuseColor = new Vector3(2f, 2f, 2f); instanceEffect = new BasicEffect(graphics.GraphicsDevice); instanceEffect.VertexColorEnabled = true; instanceEffect.TextureEnabled = false; spriteBatch = new SpriteBatch(GraphicsDevice); camera = new FirstPersonCamera(this); lowcamera = new FirstPersonCamera(this); skycamera = new FirstPersonCamera(this); DisableLodCamera(); for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++) { GamePadState state = GamePad.GetState(i); if (state.IsConnected) { activeGamePad = i; break; } } Samplers.InitRasterizers(); base.Initialize(); }
protected override void Initialize() { eng = new MainEngine(this); eng.Settings.onWindowedChanged += SwitchDisplayMode; eng.Settings.onVertexLightingChanged += UpdateEffects; eng.Settings.onAntiAliasChanged += UpdateAntiAlias; eng.Settings.onVerticalSyncChanged += UpdateVSync; graphics.GraphicsProfile = GraphicsProfile.HiDef; UpdateAntiAlias(); UpdateVSync(); graphics.ApplyChanges(); IsMouseVisible = false; spriteBatch = new SpriteBatch(GraphicsDevice); UpdateEffects(); for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++) { if (GamePad.GetState(i).IsConnected) { activeGamePad = i; break; } } Samplers.Refresh(); Samplers.InitRasterizers(); SwitchDisplayMode(); base.Initialize(); }
protected override void Update(GameTime gameTime) { if (loading == null) { LoadGame(); } newstate = GamePad.GetState(activeGamePad); newkb = Keyboard.GetState(); foreach (Kart k in karts) { k.Update(gameTime); } //x += 0.01f ; //if (x > Math.PI * 2) // x = 0; //camera.SetRotation(x, y); //Console.WriteLine(x); if (newstate.Buttons.Start == ButtonState.Pressed && newstate.Buttons.Back == ButtonState.Pressed) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.RightAlt) && Keyboard.GetState().IsKeyDown(Keys.Enter)) { if (graphics.IsFullScreen) { GoWindowed(); } else { GoFullScreen(); } } if (Keyboard.GetState().IsKeyDown(Keys.OemMinus)) { float x = camera.ViewAngle; x--; if (x < 20) { x = 20; } camera.ViewAngle = x; lowcamera.ViewAngle = x; skycamera.ViewAngle = x; } if (Keyboard.GetState().IsKeyDown(Keys.OemPlus)) { float x = camera.ViewAngle; x++; if (x > 150) { x = 150; } camera.ViewAngle = x; lowcamera.ViewAngle = x; skycamera.ViewAngle = x; } if ((newstate.Buttons.Start == ButtonState.Pressed && oldstate.Buttons.Start != newstate.Buttons.Start) || (newkb.IsKeyDown(Keys.Escape) && newkb.IsKeyDown(Keys.Escape) != oldkb.IsKeyDown(Keys.Escape))) { InMenu = !InMenu; } if (InMenu) { menu.Update(oldstate, newstate, oldkb, newkb); //currentflag = menu.items.Find(x => x.Title == "current flag: {0}").rangeval; if (menu.Exec) { switch (menu.SelectedItem.Action) { case "close": InMenu = false; break; case "load": LoadGame(); InMenu = false; break; case "link": menu.SetMenu(font); break; case "toggle": switch (menu.SelectedItem.Param) { case "inst": show_inst = !show_inst; break; case "paths": show_paths = !show_paths; break; case "lod": lodEnabled = !lodEnabled; if (lodEnabled) { EnableLodCamera(); } else { DisableLodCamera(); } break; case "antialias": graphics.PreferMultiSampling = !graphics.PreferMultiSampling; break; case "invis": HideInvisible = !HideInvisible; break; case "filter": Samplers.EnableBilinear = !Samplers.EnableBilinear; Samplers.Refresh(); break; case "wire": Samplers.EnableWireframe = !Samplers.EnableWireframe; break; case "window": if (graphics.IsFullScreen) { GoWindowed(); } else { GoFullScreen(); } break; case "lockfps": lock_fps = !lock_fps; graphics.SynchronizeWithVerticalRetrace = lock_fps; IsFixedTimeStep = lock_fps; graphics.ApplyChanges(); break; default: Console.WriteLine("unimplemented toggle: " + menu.SelectedItem.Param); break; } break; case "exit": Exit(); break; } menu.Exec = !menu.Exec; } if (newstate.Buttons.B == ButtonState.Pressed && newstate.Buttons.B != oldstate.Buttons.B) { bool togglemenu = true; foreach (MenuItem m in menu.items) { Console.WriteLine(m.Action + " " + m.Title); if (m.Action == "link" && m.Title == "BACK") { menu.SetMenu(font, m.Param); togglemenu = false; } } if (togglemenu) { InMenu = !InMenu; } } } else { foreach (MGLevel mg in levels) { mg.Update(gameTime); } if (ControlsEnabled) { UpdateCameras(gameTime); } } oldstate = newstate; oldkb = newkb; base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (loading == null) { LoadGame(); } //x += 0.01f ; //if (x > Math.PI * 2) // x = 0; //camera.SetRotation(x, y); //Console.WriteLine(x); if (IsActive) { newstate = GamePad.GetState(activeGamePad); newkb = Keyboard.GetState(); foreach (Kart k in karts) { k.Update(gameTime); } if (newstate.Buttons.Start == ButtonState.Pressed && newstate.Buttons.Back == ButtonState.Pressed) { Exit(); } if (settings.StereoPair) { if (newstate.IsButtonDown(Buttons.RightShoulder)) { settings.StereoPairSeparation += 5; } if (newstate.IsButtonDown(Buttons.LeftShoulder)) { settings.StereoPairSeparation -= 5; } if (settings.StereoPairSeparation < 0) { settings.StereoPairSeparation = 0; } if (newstate.IsButtonDown(Buttons.RightShoulder) && newstate.IsButtonDown(Buttons.LeftShoulder)) { settings.StereoPairSeparation = 130; } } if ((newkb.IsKeyDown(Keys.Enter) && newkb.IsKeyDown(Keys.RightAlt)) && !(oldkb.IsKeyDown(Keys.Enter) && newkb.IsKeyDown(Keys.RightAlt))) { settings.Windowed = !settings.Windowed; } if (Keyboard.GetState().IsKeyDown(Keys.OemMinus)) { settings.FieldOfView--; } if (Keyboard.GetState().IsKeyDown(Keys.OemPlus)) { settings.FieldOfView++; } if ((newstate.Buttons.Start == ButtonState.Pressed && oldstate.Buttons.Start != newstate.Buttons.Start) || (newkb.IsKeyDown(Keys.Escape) && newkb.IsKeyDown(Keys.Escape) != oldkb.IsKeyDown(Keys.Escape))) { InMenu = !InMenu; } if (InMenu) { menu.Update(oldstate, newstate, oldkb, newkb); //currentflag = menu.items.Find(x => x.Title == "current flag: {0}").rangeval; if (menu.Exec) { switch (menu.SelectedItem.Action) { case "close": InMenu = false; break; case "load": LoadGame(); InMenu = false; break; case "loadbig": LoadLevelFromBig(menu.SelectedItem.Value); //, 0, 2); break; case "loadbigadv": LoadLevelFromBig(menu.SelectedItem.Value, 0, 3); break; case "tod_day": TimeOfDay = new Vector3(2f); UpdateEffects(); break; case "tod_evening": TimeOfDay = new Vector3(1.7f, 1.4f, 0.7f); UpdateEffects(); break; case "tod_night": TimeOfDay = new Vector3(0.5f, 0.7f, 1.7f); UpdateEffects(); break; case "link": menu.SetMenu(font); break; case "toggle": switch (menu.SelectedItem.Param) { case "inst": settings.Models = !settings.Models; break; case "paths": settings.BotsPath = !settings.BotsPath; break; case "lod": settings.UseLowLod = !settings.UseLowLod; break; case "antialias": settings.AntiAlias = !settings.AntiAlias; break; case "invis": HideInvisible = !HideInvisible; break; case "water": HideWater = !HideWater; break; case "campos": settings.ShowCamPos = !settings.ShowCamPos; break; case "visbox": settings.VisData = !settings.VisData; break; case "visboxleaf": settings.VisDataLeaves = !settings.VisDataLeaves; break; case "filter": Samplers.EnableFiltering = !Samplers.EnableFiltering; Samplers.Refresh(); break; case "wire": Samplers.EnableWireframe = !Samplers.EnableWireframe; break; case "genmips": settings.GenerateMips = !settings.GenerateMips; break; case "window": settings.Windowed = !settings.Windowed; break; case "vcolor": settings.VertexLighting = !settings.VertexLighting; break; case "stereo": settings.StereoPair = !settings.StereoPair; break; case "sky": settings.Sky = !settings.Sky; break; case "vsync": settings.VerticalSync = !settings.VerticalSync; break; default: Console.WriteLine("unimplemented toggle: " + menu.SelectedItem.Param); break; } break; case "exit": Exit(); break; } menu.Exec = !menu.Exec; } if (newstate.Buttons.B == ButtonState.Pressed && newstate.Buttons.B != oldstate.Buttons.B) { bool togglemenu = true; foreach (MenuItem m in menu.items) { Console.WriteLine(m.Action + " " + m.Title); if (m.Action == "link" && m.Title == "BACK") { menu.SetMenu(font, m.Param); togglemenu = false; } } if (togglemenu) { InMenu = !InMenu; } } } else { foreach (MGLevel mg in MeshHigh) { mg.Update(gameTime); } if (ControlsEnabled) { UpdateCameras(gameTime); } } foreach (InstancedModel im in instanced) { im.Update(gameTime); } foreach (InstancedModel im in paths) { im.Update(gameTime); } oldms = newms; newms = Mouse.GetState(); oldstate = newstate; oldkb = newkb; } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { Window.Title = $"ctrviewer [{Math.Round(1000.0f / gameTime.ElapsedGameTime.TotalMilliseconds)} FPS]"; //if (loading == null) // LoadGame(); //x += 0.01f ; //if (x > Math.PI * 2) // x = 0; //camera.SetRotation(x, y); //Console.WriteLine(x); oldgs = newgs; oldkb = newkb; oldms = newms; newms = Mouse.GetState(); newgs = GamePad.GetState(activeGamePad); newkb = Keyboard.GetState(); if (IsActive) { newmenu.Update(gameTime, new Point(newms.X, newms.Y)); foreach (Kart k in karts) { k.Update(gameTime); } if (newgs.Buttons.Start == ButtonState.Pressed && newgs.Buttons.Back == ButtonState.Pressed) { Exit(); } if (eng.Settings.StereoPair) { if (newgs.IsButtonDown(Buttons.RightShoulder)) { eng.Settings.StereoPairSeparation += 5; } if (newgs.IsButtonDown(Buttons.LeftShoulder)) { eng.Settings.StereoPairSeparation -= 5; } if (eng.Settings.StereoPairSeparation < 0) { eng.Settings.StereoPairSeparation = 0; } if (newgs.IsButtonDown(Buttons.RightShoulder) && newgs.IsButtonDown(Buttons.LeftShoulder)) { eng.Settings.StereoPairSeparation = 130; } } if ((newkb.IsKeyDown(Keys.Enter) && newkb.IsKeyDown(Keys.RightAlt)) && !(oldkb.IsKeyDown(Keys.Enter) && newkb.IsKeyDown(Keys.RightAlt))) { eng.Settings.Windowed = !eng.Settings.Windowed; } if ( (newkb.IsKeyDown(Keys.OemTilde) && !oldkb.IsKeyDown(Keys.OemTilde)) || (newgs.IsButtonDown(Buttons.Back) && !oldgs.IsButtonDown(Buttons.Back)) ) { eng.Settings.ShowConsole = !eng.Settings.ShowConsole; } if (newkb.IsKeyDown(Keys.OemMinus)) { eng.Settings.FieldOfView--; } if (newkb.IsKeyDown(Keys.OemPlus)) { eng.Settings.FieldOfView++; } if ((newgs.Buttons.Start == ButtonState.Pressed && oldgs.Buttons.Start != newgs.Buttons.Start) || (newkb.IsKeyDown(Keys.Escape) && newkb.IsKeyDown(Keys.Escape) != oldkb.IsKeyDown(Keys.Escape))) { menu.Visible = !menu.Visible; } if (menu.Visible) { menu.Update(oldgs, newgs, oldkb, newkb); //currentflag = menu.items.Find(x => x.Title == "current flag: {0}").rangeval; if (menu.Exec) { switch (menu.SelectedItem.Action) { case "close": menu.Visible = false; break; //case "load": // LoadGame(); // InMenu = false; // break; case "loadbig": LoadLevelsFromBig(menu.SelectedItem.Value); //, 0, 2); break; case "loadbigadv": LoadLevelsFromBig(200, 203, 206, 209, 212); break; case "tod_day": SetTimeOfDay(PreferredTimeOfDay.Day); break; case "tod_evening": SetTimeOfDay(PreferredTimeOfDay.Evening); break; case "tod_night": SetTimeOfDay(PreferredTimeOfDay.Night); break; case "link": menu.SetMenu(font); break; case "setleveltype": levelType = (LevelType)menu.SelectedItem.Value; break; case "toggle": switch (menu.SelectedItem.Param) { case "inst": eng.Settings.ShowModels = !eng.Settings.ShowModels; break; case "paths": eng.Settings.ShowBotsPath = !eng.Settings.ShowBotsPath; break; case "lod": eng.Settings.UseLowLod = !eng.Settings.UseLowLod; break; case "antialias": eng.Settings.AntiAlias = !eng.Settings.AntiAlias; break; case "invis": HideInvisible = !HideInvisible; break; case "water": HideWater = !HideWater; break; case "console": eng.Settings.ShowConsole = !eng.Settings.ShowConsole; break; case "campos": eng.Settings.ShowCamPos = !eng.Settings.ShowCamPos; break; case "visbox": eng.Settings.VisData = !eng.Settings.VisData; break; case "nocull": ForceNoCulling = !ForceNoCulling; break; case "visboxleaf": eng.Settings.VisDataLeaves = !eng.Settings.VisDataLeaves; break; case "filter": Samplers.EnableFiltering = !Samplers.EnableFiltering; Samplers.Refresh(); break; case "wire": Samplers.EnableWireframe = !Samplers.EnableWireframe; break; case "genmips": eng.Settings.GenerateMips = !eng.Settings.GenerateMips; break; case "window": eng.Settings.Windowed = !eng.Settings.Windowed; break; case "vcolor": eng.Settings.VertexLighting = !eng.Settings.VertexLighting; break; case "stereo": eng.Settings.StereoPair = !eng.Settings.StereoPair; break; case "sky": eng.Settings.ShowSky = !eng.Settings.ShowSky; break; case "vsync": eng.Settings.VerticalSync = !eng.Settings.VerticalSync; break; default: GameConsole.Write("unimplemented toggle: " + menu.SelectedItem.Param); break; } break; case "exit": Exit(); break; } menu.Exec = !menu.Exec; } if ((newgs.Buttons.B == ButtonState.Pressed && newgs.Buttons.B != oldgs.Buttons.B) || (newgs.Buttons.Y == ButtonState.Pressed && newgs.Buttons.Y != oldgs.Buttons.Y)) { bool togglemenu = true; foreach (MenuItem m in menu.items) { if (m.Action == "link" && m.Title == "BACK") { menu.SetMenu(font, m.Param); togglemenu = false; } } if (togglemenu) { menu.Visible = !menu.Visible; } } } else { foreach (var mg in eng.MeshHigh) { mg.Update(gameTime); } foreach (var mg in eng.MeshLow) { mg.Update(gameTime); } foreach (var im in eng.instanced) { im.Update(gameTime); } foreach (var im in eng.paths) { im.Update(gameTime); } if (ControlsEnabled) { UpdateCameras(gameTime); } } } base.Update(gameTime); }