public StreamWriter Dump(StreamWriter w, int indent) { w.AppendIndent(indent).Write("CellCount = "); w.Write(_cells.Count); w.AppendIndent(indent).Write("Cells = {"); foreach (var entry in _cells) { w.AppendIndent(indent + 1).Write(entry.Key); w.Write(" = "); w.Dump(entry.Value, indent + 1); } w.AppendIndent(indent).Write("}"); w.AppendIndent(indent).Write("EntryCount = "); w.Write(_entryBounds.Count); w.AppendIndent(indent).Write("Entries = {"); foreach (var entry in _entryBounds) { w.AppendIndent(indent + 1).Write(entry.Key); w.Write(" = "); w.Dump(entry.Value, indent + 1); } w.AppendIndent(indent).Write("}"); return(w); }
public StreamWriter Dump(StreamWriter w, int indent) { // Write the components. w.AppendIndent(indent).Write("ComponentCount = "); w.Write(_componentIds.Count); w.AppendIndent(indent).Write("Components = {"); foreach (var component in Components) { w.AppendIndent(indent + 1).Write(component.GetType()); w.Write(" = "); w.Dump(component, indent + 1); } w.AppendIndent(indent).Write("}"); // Write systems. w.AppendIndent(indent).Write("SystemCount (excluding IDrawingSystems) = "); w.Write(_systems.Count(Packetizable.IsPacketizable)); w.AppendIndent(indent).Write("Systems = {"); for (int i = 0, j = _systems.Count; i < j; ++i) { if (!Packetizable.IsPacketizable(_systems[i])) { continue; } w.AppendIndent(indent + 1).Write(_systems[i].GetType()); w.Write(" = "); w.Dump(_systems[i], indent + 1); } w.AppendIndent(indent).Write("}"); return(w); }
public StreamWriter Dump(StreamWriter w, int indent) { w.AppendIndent(indent).Write("Trees = {"); for (var i = 0; i < _nextIndexId; ++i) { var tree = _trees[i]; if (tree == null) { continue; } w.AppendIndent(indent + 1).Write(i); w.Write(" = "); w.Dump(tree, indent + 1); } w.AppendIndent(indent).Write("}"); w.AppendIndent(indent).Write("Changed = {"); var first = true; foreach (var component in _changed) { if (!first) { w.Write(", "); } first = false; w.Write(component); } w.Write("}"); return(w); }
protected static void WriteGameState(long frame, IManager manager, string filename) { // Get some general system information, for reference. var assembly = Assembly.GetEntryAssembly().GetName(); #if DEBUG const string build = "Debug"; #else const string build = "Release"; #endif using (var w = new StreamWriter(filename)) { w.Write("--------------------------------------------------------------------------------\n"); w.Write("{0} {1} (Attached debugger: {2}) running under {3}\n", assembly.Name, build, Debugger.IsAttached, Environment.OSVersion.VersionString); w.Write("Build Version: {0}\n", assembly.Version); w.Write("CLR Version: {0}\n", Environment.Version); w.Write("CPU Count: {0}\n", Environment.ProcessorCount); w.Write("Assigned RAM: {0:0.0}MB\n", Environment.WorkingSet / 1024.0 / 1024.0); w.Write("Controller Type: Server\n"); w.Write("--------------------------------------------------------------------------------\n"); w.Write("Gamestate at frame {0}\n", frame); w.Write("--------------------------------------------------------------------------------\n"); // Dump actual game state. w.Write("Manager = "); w.Dump(manager); } }
public StreamWriter Dump(StreamWriter w, int indent) { w.AppendIndent(indent).Write("CurrentBehaviors = {"); { var first = true; foreach (var behavior in _currentBehaviors) { if (!first) { w.Write(", "); } first = false; w.Write(behavior); } } w.Write("}"); w.AppendIndent(indent).Write("Behaviors = {"); foreach (var behavior in _behaviors) { w.AppendIndent(indent + 1).Write(behavior.Key); w.Write(" = "); w.Dump(behavior.Value, indent + 1); } w.AppendIndent(indent).Write("}"); return(w); }
string[] IInformation.getDisplayText() { using (var s = new MemoryStream()) { var w = new StreamWriter(s); w.Dump(this); w.Flush(); s.Position = 0; var r = new StreamReader(s); return(new[] { r.ReadToEnd() }); } }
public StreamWriter Dump(StreamWriter w, int indent) { w.AppendIndent(indent).Write("StoredCellCount = "); w.Write(_cellInfo.Count); w.AppendIndent(indent).Write("Cells = {"); foreach (var item in _cellInfo) { w.AppendIndent(indent + 1).Write(item.Key); w.Write(" = "); w.Dump(item.Value, indent + 1); } w.AppendIndent(indent).Write("}"); return(w); }
public StreamWriter Dump(StreamWriter w, int indent) { // Write the trailing simulation. w.AppendIndent(indent).Write("TrailingSimulation = "); w.Dump(_simulations[_simulations.Length - 1], indent); // Write pending object removals. w.AppendIndent(indent).Write("PendingRemovalFrameCount = "); w.Write(_removes.Count); w.AppendIndent(indent).Write("PendingRemovals = {"); foreach (var frame in _removes) { w.AppendIndent(indent + 1).Write("Frame "); w.Write(frame.Key); w.Write(" = {"); var first = true; foreach (var entity in frame.Value) { if (!first) { w.Write(", "); } first = false; w.Write(entity); } w.Write("}"); } w.AppendIndent(indent).Write("}"); // Write pending simulation commands. w.AppendIndent(indent).Write("CommandFrameCount = "); w.Write(_commands.Count); w.AppendIndent(indent).Write("Commands = {"); foreach (var frame in _commands) { w.AppendIndent(indent + 1).Write("Frame "); w.Write(frame.Key); w.Write(" = {"); foreach (var command in frame.Value) { w.AppendIndent(indent + 1).Dump(command, indent + 1); } w.AppendIndent(indent + 1).Write("}"); } w.AppendIndent(indent).Write("}"); return(w); }
public StreamWriter Dump(StreamWriter w, int indent) { w.Write("TrailingState = "); w.Dump(_controller.Tss.TrailingSimulation, indent); return(w); }
/// <summary>Called when the specified key was pressed.</summary> /// <param name="key">The key that was pressed.</param> private void OnKeyDown(Keys key) { switch (key) { case Keys.Right: // Next test. LoadTest(_currentTest + 1); break; case Keys.Left: // Previous test LoadTest(_currentTest - 1); break; case Keys.Space: // Toggle pause. _running = !_running; break; case Keys.Tab: case Keys.Enter: // Manual step. _runOnce = true; break; case Keys.R: // Reset current test but keep camera and run settings. LoadTest(_currentTest, false); break; case Keys.K: // Create a snapshot via serialization. if (_manager != null) { // Kill the mouse joint because deserializing it would // cause a joint that we do not control anymore. if (_mouseJoint >= 0) { _manager.RemoveJoint(_mouseJoint); _mouseJoint = -1; } using (var w = new StreamWriter("before.txt")) { w.Dump(_manager); } _snapshot = new Packet(); _snapshot.Write(_manager); var hasher = new Hasher(); hasher.Write(_manager); _snapshotHash = hasher.Value; _snapshotCompressedSize = SimpleCompression.Compress(_snapshot.GetBuffer(), _snapshot.Length).Length; } break; case Keys.L: // Load a previously created snapshot. if (_snapshot != null) { // Reset test and stuff to avoid invalid references. _mouseJoint = -1; _snapshot.Reset(); _snapshot.ReadPacketizableInto(_manager); var hasher = new Hasher(); hasher.Write(_manager); Debug.Assert(_snapshotHash == hasher.Value); } break; case Keys.C: // Test copy implementation. if (_manager != null) { var copy = new Manager(); copy.AddSystem(new ContentSystem(Content)); copy.AddSystem(new PhysicsSystem(1 / UpdatesPerSecond, new Vector2(0, -10f))); copy.AddSystem(new ContentSystem(Content)); copy.AddSystem(new GraphicsDeviceSystem(_graphics)); copy.AddSystem(new DebugPhysicsRenderSystem { Enabled = true, Scale = 0.1f, Offset = new WorldPoint(0, -12) }); _manager.CopyInto(copy); _manager.Clear(); copy.CopyInto(_manager); } break; case Keys.S: // Toggle whether sleeping is allowed. _physics.AllowSleep = !_physics.AllowSleep; break; case Keys.F1: // Toggle help display. _showHelp = !_showHelp; break; case Keys.F2: // Toggle profiler information. _showProfile = !_showProfile; break; case Keys.F3: // Toggle joints. _renderer.RenderJoints = !_renderer.RenderJoints; break; case Keys.F4: // Toggle contact point and normals. _renderer.RenderContactPoints = !_renderer.RenderContactPoints; _renderer.RenderContactNormals = !_renderer.RenderContactNormals; break; case Keys.F5: // Toggle contact point normal impulse. _renderer.RenderContactPointNormalImpulse = !_renderer.RenderContactPointNormalImpulse; break; case Keys.F7: // Toggle center of mass. _renderer.RenderCenterOfMass = !_renderer.RenderCenterOfMass; break; case Keys.F8: // Toggle fixture bounding boxes. _renderer.RenderFixtureBounds = !_renderer.RenderFixtureBounds; break; } if (_manager != null) { Tests[_currentTest].OnKeyDown(key); } }
private void InitializeConsoleForDebug() { // Default handler to interpret everything that is not a command // as a script. _console.SetDefaultCommandHandler( command => { if (_client != null) { _client.Controller.PushLocalCommand(new ScriptCommand(command)); } else { _console.WriteLine("Unknown command."); } }); // Add hints for auto completion to also complete python methods. _console.AddAutoCompletionLookup(() => _client != null ? _client.GetSystem <ScriptSystem>().GlobalNames : Enumerable.Empty <string>()); _console.AddCommand( "d_dump", args => { const string filename = "dump_{0}_{1}.txt"; var id = DateTime.UtcNow.Ticks.ToString("D"); if (args.Length > 0) { id = args[1]; } while (_client.Controller.Simulation.CurrentFrame < _server.Controller.Simulation.CurrentFrame) { _client.Controller.Update(1f / 60f); } while (_server.Controller.Simulation.CurrentFrame < _client.Controller.Simulation.CurrentFrame) { _server.Controller.Update(1f / 60f); } if (_client != null) { using (var w = new StreamWriter(string.Format(filename, id, "client"))) { w.Write("Simulation = "); w.Dump(_client.Controller.Simulation); } } if (_server != null) { using (var w = new StreamWriter(string.Format(filename, id, "server"))) { w.Write("Simulation = "); w.Dump(_server.Controller.Simulation); } } }, "Writes a dump of the current game state to a file. If a name is omitted", "one will be chosen at random.", "d_dump <filename> - writes the game state dump to the specified file."); _console.AddCommand( "d_pause", args => { var paused = ParseBool(args[1]); if (_client != null) { _client.Paused = paused; } if (_server != null) { _server.Paused = paused; } }, "Sets whether to pause simulation updating. If enabled, sessions will still", "be updated, the actual simulation however will not.", "d_pause 1|0 - sets whether to pause the simulation or not."); _console.AddCommand( "d_speed", args => { _server.Controller.TargetSpeed = float.Parse(args[1]); }, "Sets the target gamespeed.", "d_speed <x> - set the target game speed to the specified value."); _console.AddCommand( "d_step", args => { var updates = args.Length > 0 ? int.Parse(args[1]) : 1; if (_client != null) { for (var i = 0; i < updates; i++) { _client.Controller.Update(1000f / Settings.TicksPerSecond); } } if (_server != null) { for (var i = 0; i < updates; i++) { _server.Controller.Update(1000f / Settings.TicksPerSecond); } } }, "Performs a single update for the server and client if they exist.", "step <frames> - applies the specified number of updates."); _console.AddCommand( "r_ai", args => { _client.GetSystem <DebugAIRenderSystem>().Enabled = ParseBool(args[1]); }, "Enables rendering debug information on AI ships.", "r_ai 1|0 - set whether to enabled rendering AI debug info."); _console.AddCommand( "r_background", args => { _client.GetSystem <BackgroundRenderSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables background rendering.", "r_background 1|0 - set whether to render the background."); _console.AddCommand( "r_entity", args => { _client.GetSystem <DebugEntityIdRenderSystem>().Enabled = ParseBool(args[1]); }, "Sets whether to render entity info at entity position.", "r_entity 1|0 - set whether to render entity info."); _console.AddCommand( "r_interpolate", args => { _client.GetSystem <InterpolationSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables position and angle interpolation for rendering.", "r_interpolate 1|0 - set whether to interpolate positions and angles."); _console.AddCommand( "r_pfx", args => { _client.GetSystem <ParticleEffectSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables particle effect rendering.", "r_pfx 1|0 - set whether to render particle effects."); _console.AddCommand( "r_postprocessing", args => { _client.GetSystem <TextureRenderSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables post-processing effects such as bloom.", "r_postprocessing 1|0 - set whether to apply post-processing effects."); _console.AddCommand( "r_physics", args => { var physics = _client.GetSystem <DebugPhysicsRenderSystem>(); var enable = ParseBool(args[2]); foreach (var c in args[1]) { switch (c) { case 'f': physics.RenderFixtures = enable; break; case 'b': physics.RenderFixtureBounds = enable; break; case 'c': physics.RenderContactPoints = enable; break; case 'm': physics.RenderCenterOfMass = enable; break; case 'n': physics.RenderContactNormals = enable; break; case 'i': physics.RenderContactPointNormalImpulse = enable; break; case 'j': physics.RenderJoints = enable; break; } } }, "Sets for which parts of the physics simulation to render debug representations for.", "r_physics [fbcmni]+ 1|0"); _console.AddCommand( "r_radar", args => { _client.GetSystem <RadarRenderSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables radar rendering.", "r_radar 1|0 - set whether to render the radar."); _console.AddCommand( "r_sound", args => { _client.GetSystem <SoundSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables sound.", "r_sound 1|0 - set whether to play sound."); _console.AddCommand( "r_textures", args => { _client.GetSystem <TextureRenderSystem>().Enabled = ParseBool(args[1]); }, "Enables or disables texture rendering.", "r_textures 1|0 - set whether to render textures."); // Copy everything written to our game console to the actual console, // too, so we can inspect it out of game, copy stuff or read it after // the game has crashed. _console.LineWritten += (sender, e) => Console.WriteLine(((LineWrittenEventArgs)e).Message); }