private static void RenderAutoComplete() { if (_suggestions.Count > 0) { var longestSuggestion = (from command in _suggestions orderby command.Length descending select command).First(); var size = FontManager.MeasureString(longestSuggestion); var x = _inputBoxRight; var y = _inputBoxBottom - 2; var lines = Math.Min(_suggestions.Count, 20); var h = (lines * 16) + 4 + 6; var w = size + 4 + 6; Renderer2D.FillRectangle(new Color(0x44, 0x44, 0x44), x, y, w, h); Renderer2D.DrawRectangle(new Color(0x22, 0x22, 0x22), x, y, w, h); foreach (var line in _suggestions) { FontManager.SetColor(Color.White); FontManager.PrintString(new Vector2(x + 5, y + 5), line); y += 16; } } }
protected override void LoadContent() { ConsoleRenderer.Initialize(); StyleManager.CreateTextures(GraphicsDevice); MapRenderer.Initialize(GraphicsDevice); DeferredRenderer.Initialize(GraphicsDevice); Renderer2D.Initialize(GraphicsDevice); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } Camera.Process(); // camera moving float dT = (float)(gameTime.ElapsedGameTime.TotalMilliseconds / 1000); Vector3 delta = new Vector3(); KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Right)) { delta += new Vector3(3.0f * dT, 0, 0); } if (keyState.IsKeyDown(Keys.Left)) { delta += new Vector3(-3.0f * dT, 0, 0); } if (keyState.IsKeyDown(Keys.Up)) { delta += new Vector3(0, 3.0f * dT, 0); } if (keyState.IsKeyDown(Keys.Down)) { delta += new Vector3(0, -3.0f * dT, 0); } if (keyState.IsKeyDown(Keys.PageUp)) { delta += new Vector3(0, 0, -3.0f * dT); } if (keyState.IsKeyDown(Keys.PageDown)) { delta += new Vector3(0, 0, 3.0f * dT); } Camera.MainCamera.Position += delta; if (Camera.MainCamera.Position.X > 255) { Camera.MainCamera.Position = new Vector3(4.0f, 40.0f, 12.0f); } Renderer2D.InitPerFrame(); ConsoleRenderer.Process(); base.Update(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0); DeferredRenderer.Render3DStuff(GraphicsDevice); Renderer2D.Render(GraphicsDevice); base.Draw(gameTime); }
private static void RenderOutputBox() { int x = 15; int y = _inputBoxBottom + 5; int w = _screenX - 30; int h = _screenY - y - 15 - 2; var size = 16; Renderer2D.FillRectangle(new Color(0x44, 0x44, 0x44, 0xcc), x, y, w + 2, h + 2); Renderer2D.DrawRectangle(new Color(0x22, 0x22, 0x22, 0xcc), x, y, w + 2, h + 2); bool reset = false; if (_screenSize == 0) { reset = true; } _screenSize = (h - 4) / 16; if (reset) { ResetTop(); } var list = _screenBuffer.Skip(_screenTop); int i = 0; y += 5; foreach (var line in list) { FontManager.SetColor(Color.White); FontManager.PrintString(new Vector2(x + 5, y), line); y += size; i++; if (i >= _screenSize) { break; } } }
private static void RenderInputBox() { var text = "GBH2>^7 " + _inputBuffer; var tSize = FontManager.MeasureString(text); int x = 15; int y = 15; int w = _screenX - 30; int h = 16 + 3 + 3; Renderer2D.FillRectangle(new Color(0x44, 0x44, 0x44), x, y, w + 2, h + 2); Renderer2D.DrawRectangle(new Color(0x22, 0x22, 0x22), x, y, w + 2, h + 2); FontManager.SetColor(Color.Yellow); FontManager.PrintString(new Vector2(x + 7, y + 3), text); _inputBoxRight = x + 7 + tSize; _inputBoxBottom = y + h + 2; }
public static void Process() { // limit FPS and handle events int minMsec = (com_maxFPS.GetValue <int>() > 0) ? (1000 / com_maxFPS.GetValue <int>()) : 1; uint msec = 0; do { _frameTime = EventSystem.HandleEvents(); msec = _frameTime - _lastTime; } while (msec < minMsec); // handle time scaling var scale = timescale.GetValue <float>(); msec = (uint)(msec * scale); if (msec < 1) { msec = 1; } else if (msec > 5000) { msec = 5000; } if (msec > 500) { Log.Write(LogLevel.Info, "Hitch warning: {0} msec frame time", msec); } DeltaTime = msec / 1000f; FrameMsec = msec; _lastTime = _frameTime; // process the command buffer Command.ExecuteBuffer(); // handle network stuff NetManager.Process(); // process game stuff Server.Process(); // process client Client.Process(); // more stuff (needs to be moved) Camera.Process(); if (!sv_running.GetValue <bool>()) { CellManager.Recenter(new[] { Camera.MainCamera.Position }); } Renderer2D.InitPerFrame(); FontManager.SetColor(Color.White); // camera moving DebugCamera.Process(); ConsoleRenderer.Process(); // render stuff if (Renderer.MakeDeviceAvailable()) { Renderer.Clear(); if (Client.State == Client.ClientState.Ingame) { DeferredRenderer.Render3DStuff(Renderer.Device); } Renderer2D.Render(Renderer.Device); Renderer.Device.Present(); } }
public static void Initialize() { // set the current culture to the invariant culture Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // initialize the logging service Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); Log.AddListener(new GameLogListener()); Log.AddListener(new FileLogListener("GBHGame.log", false)); Log.Write(LogLevel.Info, "GBH2 v0 initializing"); Log.Write(LogLevel.Critical, "jeremych is an egghead and a nabsalad"); ConVar.Initialize(); FileSystem.Initialize(); Win32System.Initialize(); MapGeometry.Initialize(); //StyleManager.Load("Styles/bil.sty"); //MapManager.Load("Maps/MP1-comp.gmp"); Camera.Initialize(); NetManager.Initialize(29960); Client.Initialize(); Server.Initialize(); GameWindow.Initialize(); com_maxFPS = ConVar.Register("com_maxFPS", 0, "Maximum framerate for the game loop.", ConVarFlags.Archived); timescale = ConVar.Register("timescale", 1.0f, "Scale time by this amount", ConVarFlags.Cheat); sv_running = ConVar.Register("sv_running", true, "Is the server running?", ConVarFlags.ReadOnly); cl_running = ConVar.Register("cl_running", false, "Is the client running?", ConVarFlags.ReadOnly); sv_paused = ConVar.Register("sv_paused", false, "Is the server paused?", ConVarFlags.ReadOnly); cl_paused = ConVar.Register("cl_paused", false, "Is the client paused?", ConVarFlags.ReadOnly); net_showpackets = ConVar.Register("net_showpackets", false, "Show network packets.", ConVarFlags.None); mapname = ConVar.Register("mapname", "", "Current mapname", ConVarFlags.ReadOnly); nickname = ConVar.Register("nickname", Environment.GetEnvironmentVariable("username"), "Your nickname", ConVarFlags.Archived); Renderer.Initialize(); MaterialManager.ReadMaterialFile("base.material"); MaterialManager.ReadMaterialFile("Styles/bil.material"); ConsoleRenderer.Initialize(); //StyleManager.CreateTextures(Renderer.Device); MapRenderer.Initialize(Renderer.Device); DeferredRenderer.Initialize(Renderer.Device); Renderer2D.Initialize(Renderer.Device); // jeez, people these days just need to get a *proper* nickname if (ConVar.GetValue <string>("nicknamee") == Environment.GetEnvironmentVariable("username")) { Log.Write(LogLevel.Info, "It looks it's your first time running GBH2. Please type 'nickname <WANTED NICKNAME>' to set your nickname."); } var path = Directory.GetCurrentDirectory() + "\\config.ini"; IniFile ini = new IniFile(path); var value = ini.IniReadValue("CONFIG", "nickname"); if (value != null) { ConVar.SetValue <string>("nicknamee", value); } }