Show More
Commit Description:
Add details about architecture.
Commit Description:
Add details about architecture.
References:
File last commit:
Show/Diff file:
Action:
isometric-park-fna/FNAGame.cs
1040 lines | 40.2 KiB | text/x-csharp | CSharpLexer
1040 lines | 40.2 KiB | text/x-csharp | CSharpLexer
r301 | using Microsoft.Xna.Framework; | |||
r1 | using Microsoft.Xna.Framework.Audio; | |||
using Microsoft.Xna.Framework.Input; | ||||
using Microsoft.Xna.Framework.Graphics; | ||||
using Microsoft.Xna.Framework.Media; | ||||
using System; | ||||
using System.IO; | ||||
r301 | using System.Reflection; | |||
using System.Diagnostics; | ||||
using System.Collections.Generic; | ||||
using System.Linq; | ||||
r1 | using SpriteFontPlus; | |||
r405 | ||||
r1 | using isometricparkfna; | |||
r66 | using static isometricparkfna.CellMap; | |||
r32 | using isometricparkfna.Utils; | |||
r70 | using isometricparkfna.UI; | |||
r170 | using isometricparkfna.Engines; | |||
r174 | using isometricparkfna.Components; | |||
r189 | using isometricparkfna.Renderers; | |||
r193 | using isometricparkfna.Messages; | |||
using isometricparkfna.Spawners; | ||||
r298 | using Num = System.Numerics; | |||
r30 | ||||
r16 | using ImGuiNET.SampleProgram.XNA; | |||
r18 | using ImGuiNET; | |||
r505 | using ImPlotNET; | |||
r44 | using TraceryNet; | |||
r169 | using Encompass; | |||
r405 | using Ink.Runtime; | |||
r4 | ||||
r301 | //Let's let core builds be deterministic | |||
#if NETCOREAPP | ||||
r491 | [assembly:AssemblyVersion("0.36.31.0")] | |||
r301 | #else | |||
r491 | [assembly:AssemblyVersion("0.36.31.*")] | |||
r301 | #endif | |||
r1 | class FNAGame : Game | |||
{ | ||||
r101 | private KeyboardState keyboardPrev = new KeyboardState(); | |||
r295 | private MouseState mousePrev = new MouseState(); | |||
r1 | ||||
r101 | private SpriteBatch batch; | |||
r527 | private SpriteBatch tileBatch; | |||
r470 | #if DEBUG | |||
r101 | private SoundEffect sound; | |||
r470 | #endif | |||
r101 | private SpriteFont monoFont; | |||
r297 | private SpriteFont largeMonoFont; | |||
r1 | ||||
r514 | private Camera camera = new Camera(new float[] {0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f }); | |||
r4 | ||||
r101 | Random random_generator = new Random(); | |||
r4 | ||||
r101 | int frameRate = 0; | |||
int frameCounter = 0; | ||||
TimeSpan elapsedTime = TimeSpan.Zero; | ||||
TimeSpan drawTime = TimeSpan.Zero; | ||||
r514 | TimeSpan tileDrawTime = TimeSpan.Zero; | |||
TimeSpan gridDrawTime = TimeSpan.Zero; | ||||
TimeSpan treeDrawTime = TimeSpan.Zero; | ||||
r101 | TimeSpan updateTime = TimeSpan.Zero; | |||
r49 | ||||
r101 | Queue<float> past_fps = new Queue<float>(100); | |||
r518 | Queue<TimeSpan> past_draw = new Queue<TimeSpan>(100); | |||
r101 | int tilesDrawn = 0; | |||
r1 | ||||
r307 | private static int width = 1280; | |||
private static int height = 640; | ||||
r1 | ||||
r101 | //new tile stuff | |||
r514 | int squaresAcross = 200; | |||
int squaresDown = 200; | ||||
r348 | ||||
r101 | Simulation simulation; | |||
r9 | ||||
r192 | public Vector2 mouseGrid; | |||
r101 | Vector2 original_point; | |||
r192 | //for now | |||
public bool in_zone; | ||||
r297 | public bool in_active_zone; | |||
r541 | public bool in_preserve; | |||
r297 | ||||
public bool isPlaying = false; | ||||
r192 | ||||
r101 | private ImGuiRenderer _imGuiRenderer; | |||
private DebugWindow debugWindow; | ||||
r30 | ||||
r411 | public ImGuiImageMap imageMap; | |||
r423 | public ImGuiImageMap portraitsMap; | |||
r122 | ||||
r170 | public bool show_another_window; | |||
r1 | ||||
r405 | public Story Story; | |||
r101 | //buggy | |||
r20 | private static bool enableCulling = false; | |||
r19 | ||||
r114 | private List<NewsItem> newsItems; | |||
r43 | ||||
r32 | ||||
r171 | public bool showGrid; | |||
public bool showTrees; | ||||
r44 | private Grammar grammar; | |||
r33 | private string output; | |||
r49 | private GraphicsDeviceManager gdm; | |||
r171 | public bool showBudget; | |||
r52 | private BudgetWindow budgetWindow; | |||
r21 | ||||
r169 | //Encompass | |||
private WorldBuilder WorldBuilder = new WorldBuilder(); | ||||
private World World; | ||||
r186 | private ImGuiWindowBridgeEngine imGuiWindowBridgeEngine; | |||
r21 | ||||
r463 | public bool quit = false; | |||
r405 | ||||
r19 | private static void Main(string[] args) | |||
r101 | { | |||
r462 | #if NETCOREAPP | |||
r101 | DllMap.Initialise(false); | |||
r462 | #endif | |||
r400 | try { | |||
using FNAGame g = new FNAGame(); | ||||
g.Run(); | ||||
} | ||||
catch (Exception e) | ||||
{ | ||||
Logging.Critical(string.Format("Unhandled exception: {0}", e)); | ||||
return; | ||||
} | ||||
r280 | ||||
r462 | #if !DEBUG | |||
r280 | Logging.logFile.Close(); | |||
File.Delete(Logging.logFileName); | ||||
r462 | #endif | |||
r101 | } | |||
r1 | ||||
r101 | private FNAGame() | |||
{ | ||||
r100 | ||||
r30 | #if DEBUG | |||
r101 | foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) | |||
{ | ||||
r497 | Logging.Debug("Loaded: " + assembly.ToString() + "\n"); | |||
r101 | } | |||
; | ||||
r232 | ||||
r30 | #endif | |||
r101 | this.gdm = new GraphicsDeviceManager(this) { | |||
// Typically you would load a config here... | ||||
PreferredBackBufferWidth = width, | ||||
PreferredBackBufferHeight = height, | ||||
IsFullScreen = false, | ||||
SynchronizeWithVerticalRetrace = true | ||||
}; | ||||
IsFixedTimeStep = false; | ||||
r1 | ||||
r497 | this.simulation = new Simulation(this.squaresAcross, this.squaresDown, new float[] {16.66667f*240, 16.66667f*120, 16.66667f*60, 16.66667f*30, 16.66667f*1 }); | |||
r9 | ||||
r101 | showBudget = false; | |||
showGrid = true; | ||||
r152 | showTrees = true; | |||
r18 | ||||
r101 | this.Window.Title = "Isometric Park"; | |||
r30 | ||||
r101 | Content.RootDirectory = "Content"; | |||
} | ||||
r1 | ||||
r369 | protected override void Initialize() | |||
r101 | { | |||
/* This is a nice place to start up the engine, after | ||||
* loading configuration stuff in the constructor | ||||
*/ | ||||
this.IsMouseVisible = true; | ||||
_imGuiRenderer = new ImGuiRenderer(this); | ||||
_imGuiRenderer.RebuildFontAtlas(); // Required so fonts are available for rendering | ||||
r1 | ||||
r101 | base.Initialize(); | |||
} | ||||
r1 | ||||
r101 | protected override void LoadContent() | |||
{ | ||||
// Create the batch... | ||||
r527 | this.batch = new SpriteBatch(GraphicsDevice); | |||
this.tileBatch = new SpriteBatch(GraphicsDevice); | ||||
r1 | ||||
r470 | #if DEBUG | |||
r101 | sound = Content.Load<SoundEffect>("FNASound"); | |||
r470 | #endif | |||
r523 | // Tile.TileSetTexture = Content.Load<Texture2D>(@"part4_tileset"); | |||
Tile.TileSetTexture = Content.Load<Texture2D>(@"merged_tileset"); | ||||
r206 | var texture = Content.Load<Texture2D>(@"solid_tileset"); | |||
r101 | ||||
r412 | var imageMapTexture = Content.Load<Texture2D>(@"photos_converted3"); | |||
r428 | this.imageMap = new ImGuiImageMap(500, 400, imageMapTexture, _imGuiRenderer, null); | |||
r101 | ||||
r423 | var portraitMapTexture = Content.Load<Texture2D>(@"portraits"); | |||
r428 | this.portraitsMap = new ImGuiImageMap(300, 400, portraitMapTexture, _imGuiRenderer, @"Content/portraits.yaml"); | |||
r423 | ||||
r101 | Line.initialize(GraphicsDevice); | |||
r206 | Quad.Initialize(GraphicsDevice, texture); | |||
r272 | Logging.Success("Initialized Quad texture."); | |||
r248 | ContractWindow.LoadContent(this._imGuiRenderer, this.imageMap); | |||
r423 | DialogInterface.LoadContent(this._imGuiRenderer, this.portraitsMap); | |||
r1 | ||||
r350 | //Must be done before SetFontMessage is sent | |||
var bakedMono = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), | ||||
r462 | 15, | |||
1024, | ||||
1024, | ||||
new[] | ||||
{ | ||||
CharacterRange.BasicLatin, | ||||
CharacterRange.Latin1Supplement, | ||||
CharacterRange.LatinExtendedA, | ||||
CharacterRange.Cyrillic, | ||||
CharacterRange.LatinExtendedB, | ||||
new CharacterRange((char) 0x00B7) | ||||
} | ||||
); | ||||
r350 | ||||
var bakedMonoLarge = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), | ||||
r462 | 30, | |||
1024, | ||||
1024, | ||||
new[] | ||||
{ | ||||
CharacterRange.BasicLatin, | ||||
CharacterRange.Latin1Supplement, | ||||
CharacterRange.LatinExtendedA, | ||||
CharacterRange.Cyrillic, | ||||
CharacterRange.LatinExtendedB, | ||||
new CharacterRange((char) 0x00B7) | ||||
} | ||||
); | ||||
r350 | monoFont = bakedMono.CreateSpriteFont(GraphicsDevice); | |||
largeMonoFont = bakedMonoLarge.CreateSpriteFont(GraphicsDevice); | ||||
r194 | //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded: | |||
r248 | this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice, this.imageMap); | |||
r194 | ||||
r231 | //Has to happen before Encompass stuff, so Spawners can use the grammar: | |||
var json2 = new FileInfo(@"Content/grammar.json"); | ||||
this.grammar = new TraceryNet.Grammar(json2); | ||||
r375 | //Has to happen after Grammar initialization. | |||
NewGameWindow.Initialize(this.grammar); | ||||
r174 | ||||
r405 | this.Story = new Story(File.ReadAllText(@"Content/dialog.json")); | |||
r488 | //Bindings have to | |||
r484 | Story.BindExternalFunction ("endGame", () => { | |||
r488 | Logging.Success("endGame"); | |||
this.imGuiWindowBridgeEngine.gameStateMessages.Add(new GameStateMessage {isPlaying = false}); | ||||
this.imGuiWindowBridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage {Window = isometricparkfna.Messages.Window.MainMenu}); | ||||
}); | ||||
r405 | ||||
Logging.Debug(this.Story.ContinueMaximally()); | ||||
r312 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm)); | |||
r405 | WorldBuilder.AddEngine(new UIEngine(this.Story)); | |||
WorldBuilder.AddEngine(new DialogEngine(this.Story, this.grammar)); | ||||
r194 | ||||
r408 | WorldBuilder.AddEngine(new EventEngine()); | |||
r350 | var gameBridgeEngine = new GameBridgeEngine(this); | |||
WorldBuilder.AddEngine(gameBridgeEngine); | ||||
r303 | WorldBuilder.AddEngine(new GameStateEngine()); | |||
r204 | WorldBuilder.AddEngine(this.simulation.BridgeEngine); | |||
r178 | WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera)); | |||
r389 | this.imGuiWindowBridgeEngine = new ImGuiWindowBridgeEngine(this.debugWindow, debugWindow.monoFont, debugWindow.italicFont, this.simulation); | |||
r186 | WorldBuilder.AddEngine(this.imGuiWindowBridgeEngine); | |||
r218 | WorldBuilder.AddEngine(new ContractStatusEngine(this.simulation)); | |||
r194 | ||||
r231 | WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar)); | |||
r365 | WorldBuilder.AddEngine(new GameSpawner(this.simulation, this, this.grammar)); | |||
r254 | WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar)); | |||
r405 | WorldBuilder.AddEngine(new DialogSpawner(this.Story, this.grammar)); | |||
r359 | WorldBuilder.AddEngine(new PolicyEngine()); | |||
r365 | WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar)); | |||
r460 | WorldBuilder.AddEngine(new SimulationGameRateBridgeEngine(this.simulation)); | |||
r538 | WorldBuilder.AddEngine(new BuildToolEngine(this.simulation.map)); | |||
r174 | ||||
r527 | WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1); | |||
r462 | WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2); | |||
r194 | var contractWindow = WorldBuilder.CreateEntity(); | |||
r200 | WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false }); | |||
WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts }); | ||||
r194 | ||||
r197 | var forestWindow = WorldBuilder.CreateEntity(); | |||
r200 | WorldBuilder.SetComponent(forestWindow, new VisibilityComponent { visible = false }); | |||
WorldBuilder.SetComponent(forestWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Forest }); | ||||
r197 | ||||
var newsWindow = WorldBuilder.CreateEntity(); | ||||
r200 | WorldBuilder.SetComponent(newsWindow, new VisibilityComponent { visible = false }); | |||
WorldBuilder.SetComponent(newsWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.News }); | ||||
r197 | ||||
r303 | var mainMenu = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(mainMenu, new VisibilityComponent { visible = true }); | ||||
WorldBuilder.SetComponent(mainMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.MainMenu }); | ||||
r305 | var inputMenu = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(inputMenu, new VisibilityComponent { visible = false }); | ||||
WorldBuilder.SetComponent(inputMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.InGameMenu }); | ||||
r307 | var optionsWindow = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(optionsWindow, new VisibilityComponent { visible = false }); | ||||
WorldBuilder.SetComponent(optionsWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Options }); | ||||
r361 | var newGameWindow = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(newGameWindow, new VisibilityComponent { visible = false }); | ||||
WorldBuilder.SetComponent(newGameWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.NewGame }); | ||||
r503 | var graphWindow = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(graphWindow, new VisibilityComponent { visible = false }); | ||||
WorldBuilder.SetComponent(graphWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Graph }); | ||||
r543 | var preserveTool = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(preserveTool, new ToolComponent { Tool = Tool.Preserve }); | ||||
WorldBuilder.SetComponent(preserveTool, new SelectedComponent {Type = SelectionType.Tool, selected = true}); | ||||
r305 | ||||
r462 | var gameEntity = WorldBuilder.CreateEntity(); | |||
r350 | ||||
r462 | WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); | |||
r306 | ||||
r462 | var policyEntity = WorldBuilder.CreateEntity(); | |||
WorldBuilder.SetComponent(policyEntity, | ||||
new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement}); | ||||
WorldBuilder.SetComponent(policyEntity, | ||||
new BudgetLineComponent { }); | ||||
r350 | try { | |||
r462 | var options = Options.readOptions(); | |||
r200 | ||||
r462 | this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage { | |||
r350 | fontSize = options.fontSize, | |||
r462 | fontName = options.fontName | |||
}); | ||||
r417 | ||||
r462 | WorldBuilder.SetComponent(gameEntity, new OptionsComponent {ProfanitySetting = options.profanitySetting}); | |||
r417 | ||||
OptionsWindow.Initialize(new Vector2(FNAGame.width, FNAGame.height), gdm.IsFullScreen, options.profanitySetting); | ||||
r462 | Logging.Success("Loaded options."); | |||
r417 | ||||
r350 | } | |||
catch (FileNotFoundException e) | ||||
{ | ||||
r370 | Logging.Error(String.Format("Error loading file: {0}", e.ToString())); | |||
r350 | } | |||
r17 | ||||
r350 | World = WorldBuilder.Build(); | |||
r297 | ||||
r101 | this.output = grammar.Flatten("#greeting#"); | |||
r458 | var result = grammar.Flatten("#[assistantName:#assistantNames#][friendOfThePark:#assistantNames#][whatever:whatever]vars#"); | |||
r44 | ||||
r200 | Func<string, string> toUpper = delegate (string i) | |||
{ | ||||
return i.ToUpper(); | ||||
}; | ||||
r113 | ||||
r200 | grammar.AddModifier("toUpper", toUpper); | |||
r113 | ||||
r200 | var newItems = new[] {new NewsItem{hed="Test", contents="#city.toUpper# - This is where the lede would go. #whatever#", source="Wire"} | |||
r462 | }; | |||
r114 | ||||
r200 | this.newsItems = newItems.ToList(); | |||
r115 | ||||
r200 | using (var sr = new StreamReader(@"Content/news_items.yaml")) | |||
{ | ||||
this.newsItems.AddRange(NewsItem.FromYaml(sr.ReadToEnd())); | ||||
} | ||||
using (var sr_pregenerated = new StreamReader(@"Content/news_items_pregenerated.yaml")) | ||||
{ | ||||
this.newsItems.AddRange(NewsItem.FromYaml(sr_pregenerated.ReadToEnd())); | ||||
} | ||||
this.simulation.LoadContent(this.newsItems, this.grammar); | ||||
r113 | ||||
r101 | this.budgetWindow = new BudgetWindow(new Budget { }, this.monoFont, 0, 0); | |||
r52 | ||||
r235 | Logging.Success("Content loaded."); | |||
r101 | } | |||
r1 | ||||
r345 | ||||
public void setFont(string font, int size) | ||||
{ | ||||
r348 | var font_path = DebugWindow.fonts[font]; | |||
r345 | ||||
r354 | var baked = TtfFontBaker.Bake(File.OpenRead(font_path), | |||
r462 | size, | |||
1024, | ||||
1024, | ||||
new[] | ||||
{ | ||||
CharacterRange.BasicLatin, | ||||
CharacterRange.Latin1Supplement, | ||||
CharacterRange.LatinExtendedA, | ||||
CharacterRange.Cyrillic, | ||||
CharacterRange.LatinExtendedB, | ||||
new CharacterRange((char) 0x00B7) | ||||
} | ||||
); | ||||
r345 | ||||
r348 | this.monoFont = baked.CreateSpriteFont(GraphicsDevice); | |||
r345 | } | |||
r348 | ||||
r200 | ||||
r101 | protected override void UnloadContent() | |||
{ | ||||
batch.Dispose(); | ||||
r470 | #if DEBUG | |||
r101 | sound.Dispose(); | |||
r470 | #endif | |||
r101 | Tile.TileSetTexture.Dispose(); | |||
r272 | Logging.Success("Disposed of Tile texture."); | |||
if (Quad.PixelTexture != null) | ||||
{ | ||||
Quad.PixelTexture.Dispose(); | ||||
Logging.Success("Disposed of Pixel texture."); | ||||
} | ||||
if (Quad.SolidTexture != null) | ||||
{ | ||||
r462 | Quad.SolidTexture.Dispose(); | |||
r272 | } | |||
r101 | } | |||
r1 | ||||
r101 | Vector2 calculateMousegrid(Vector2 normalizedMousePos) | |||
{ | ||||
Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); | ||||
Vector2 adjustedMousePos = normalizedMousePos - adjust; | ||||
r12 | ||||
r101 | float boardx = ((adjustedMousePos.X / Tile.TileSpriteWidth) + (adjustedMousePos.Y / Tile.TileSpriteHeight)); | |||
float boardy = ((adjustedMousePos.Y / Tile.TileSpriteHeight) - (adjustedMousePos.X / Tile.TileSpriteWidth)); | ||||
r12 | ||||
r101 | return new Vector2((int)boardx, (int)boardy); | |||
} | ||||
r11 | ||||
r1 | ||||
r541 | private String CurrentStatus() { | |||
if (this.in_active_zone) { | ||||
return "Contracted"; | ||||
} | ||||
else if (this.in_zone) { | ||||
return "Proposed Contract"; | ||||
} | ||||
else if (this.in_preserve) { | ||||
return "Preserve"; | ||||
} | ||||
else { | ||||
return "Unused"; | ||||
} | ||||
} | ||||
r1 | ||||
r101 | protected override void Update(GameTime gameTime) | |||
{ | ||||
Stopwatch stopWatch = new Stopwatch(); | ||||
stopWatch.Start(); | ||||
r50 | ||||
r480 | #if DEBUG | |||
r101 | float volume = 1.0f; | |||
float pitch = 0.0f; | ||||
float pan = 0.0f; | ||||
r480 | #endif | |||
r1 | ||||
r101 | KeyboardState keyboardCur = Keyboard.GetState(); | |||
r296 | MouseState mouseCur = Mouse.GetState(); | |||
r348 | ||||
r462 | #region input | |||
r481 | ||||
r462 | #region misc_keys | |||
r470 | #if DEBUG | |||
r349 | if (keyboardCur.IsKeyDown(Keys.OemBackslash) | |||
&& keyboardPrev.IsKeyUp(Keys.OemBackslash) | ||||
&& keyboardCur.IsKeyDown(Keys.LeftShift)) | ||||
r348 | { | |||
sound.Play(volume, pitch, pan); | ||||
} | ||||
r470 | #endif | |||
r462 | #endregion misc_keys | |||
#endregion input | ||||
r12 | ||||
r169 | World.Update(gameTime.ElapsedGameTime.TotalSeconds); | |||
r348 | this.simulation.update(gameTime.ElapsedGameTime); | |||
r11 | ||||
r348 | if (this.showBudget) | |||
{ | ||||
this.showBudget = this.budgetWindow.update(mouseCur, this.simulation.latestBudget, this.simulation.previousBudget); | ||||
} | ||||
r52 | ||||
r43 | ||||
r348 | this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice))); | |||
r11 | ||||
r348 | this.mouseGrid = this.calculateMousegrid(this.original_point); | |||
r11 | ||||
r348 | elapsedTime += gameTime.ElapsedGameTime; | |||
r1 | ||||
r348 | if (elapsedTime > TimeSpan.FromSeconds(1)) | |||
{ | ||||
elapsedTime -= TimeSpan.FromSeconds(1); | ||||
frameRate = frameCounter; | ||||
frameCounter = 0; | ||||
} | ||||
r1 | ||||
r348 | this.keyboardPrev = keyboardCur; | |||
this.mousePrev = mouseCur; | ||||
r7 | ||||
r348 | stopWatch.Stop(); | |||
this.updateTime = stopWatch.Elapsed; | ||||
r50 | ||||
r348 | base.Update(gameTime); | |||
r1 | ||||
r463 | if (quit) { | |||
this.Exit(); | ||||
} | ||||
r348 | } | |||
r1 | ||||
r348 | protected float calculateDepth() { | |||
return ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; | ||||
} | ||||
r68 | ||||
r348 | protected Boolean cull(int gridX, int gridY) | |||
{ | ||||
int screenX = (gridX - gridY) * Tile.TileSpriteWidth / 2; | ||||
int screenY = (gridX + gridY) * Tile.TileSpriteHeight / 2; | ||||
r19 | ||||
r348 | Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice)); | |||
r19 | ||||
r348 | return (!FNAGame.enableCulling || | |||
(MathUtils.BetweenExclusive(original.X, -Tile.TileSpriteWidth, FNAGame.width) | ||||
&& MathUtils.BetweenExclusive(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); | ||||
} | ||||
r19 | ||||
r68 | //Convenience method I'm not super sure about anymore. | |||
protected void drawTileAt(int x, int y, int tileIndex, int height) | ||||
r101 | { | |||
float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; | ||||
r67 | ||||
r526 | float depthOffset = 0.7f - ((x + (y * Tile.TileWidth)) / maxdepth); | |||
r67 | ||||
r527 | Tile.drawTileAt(this.tileBatch, x, y, tileIndex, height, depthOffset); | |||
r101 | } | |||
r67 | ||||
r4 | ||||
r101 | protected override void Draw(GameTime gameTime) | |||
r46 | { | |||
frameCounter++; | ||||
r1 | ||||
r46 | string fps = string.Format("fps: {0}", frameRate); | |||
r297 | bool has_tree = false; | |||
r1 | ||||
r46 | Stopwatch stopWatch = new Stopwatch(); | |||
stopWatch.Start(); | ||||
GraphicsDevice.Clear(Color.CornflowerBlue); | ||||
r297 | ||||
_imGuiRenderer.BeforeLayout(gameTime); | ||||
r348 | if (this.isPlaying) | |||
r369 | { | |||
r516 | batch.Begin(SpriteSortMode.Deferred, | |||
r462 | BlendState.AlphaBlend, | |||
null, | ||||
null, | ||||
null, | ||||
null, | ||||
camera.get_transformation(GraphicsDevice)); | ||||
r1 | ||||
r12 | ||||
r462 | #region draw_tiles | |||
r514 | Stopwatch stopWatch2 = new Stopwatch(); | |||
stopWatch2.Start(); | ||||
r462 | //reset | |||
this.tilesDrawn = 0; | ||||
r16 | ||||
r517 | var scale_factor = 1; | |||
var x_adjust = scale_factor > 1 ? -scale_factor : 0; | ||||
var y_adjust = scale_factor > 1 ? -scale_factor/2 : 0; | ||||
for (int y = y_adjust; y < this.squaresDown + y_adjust; y += scale_factor) | ||||
r46 | { | |||
r517 | for (int x = x_adjust; x < this.squaresAcross + x_adjust; x += scale_factor) | |||
r462 | { | |||
r517 | int screenx = (x - y) * (Tile.TileSpriteWidth) / 2 - 3*scale_factor; | |||
int screeny = (x + y) * (Tile.TileSpriteHeight) / 2; | ||||
r12 | ||||
r515 | // if (this.cull(x, y)) | |||
// { | ||||
r534 | batch.Draw( | |||
Tile.TileSetTexture, | ||||
new Rectangle( | ||||
screenx, | ||||
screeny, | ||||
Tile.TileWidth * scale_factor, Tile.TileHeight * scale_factor), | ||||
Tile.GetSourceRectangle(1), | ||||
Color.White, | ||||
0.0f, | ||||
Vector2.Zero, | ||||
SpriteEffects.None, | ||||
0.9f); | ||||
r19 | ||||
r534 | this.tilesDrawn++; | |||
r515 | // } | |||
r46 | } | |||
} | ||||
r516 | batch.End(); | |||
r514 | stopWatch2.Stop(); | |||
this.tileDrawTime = stopWatch2.Elapsed; | ||||
r462 | #endregion draw_tiles | |||
r12 | ||||
r462 | #region draw_gridlines | |||
r526 | batch.Begin(SpriteSortMode.Deferred, | |||
r516 | BlendState.AlphaBlend, | |||
null, | ||||
null, | ||||
null, | ||||
null, | ||||
camera.get_transformation(GraphicsDevice)); | ||||
r514 | stopWatch2 = new Stopwatch(); | |||
stopWatch2.Start(); | ||||
r34 | ||||
r462 | if (this.showGrid) | |||
r46 | { | |||
r462 | //need to go one extra so gridlines include the far side of the final tile: | |||
for (int y = 0; y < (this.squaresDown + 1); y++) | ||||
{ | ||||
r12 | ||||
r462 | Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved | |||
Line.drawLine(batch, | ||||
new Vector2(((0 - y) * Tile.TileSpriteWidth / 2), | ||||
(0 + y) * Tile.TileSpriteHeight / 2) + adjust, | ||||
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), | ||||
new Vector2((this.squaresAcross - (y)) * Tile.TileSpriteWidth / 2, | ||||
(this.squaresAcross + (y)) * Tile.TileSpriteHeight / 2) + adjust, | ||||
r12 | ||||
r462 | Color.White, 0.81f);//Just below the highlighted square and areas | |||
} | ||||
r101 | ||||
r462 | for (int x = 0; x < (this.squaresAcross + 1); x++) | |||
{ | ||||
r12 | ||||
r462 | Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved | |||
r12 | ||||
r462 | Line.drawLine(batch, | |||
new Vector2(((x - 0) * Tile.TileSpriteWidth / 2), (x + 0) * Tile.TileSpriteHeight / 2) + adjust, | ||||
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), | ||||
new Vector2((x - this.squaresDown) * Tile.TileSpriteWidth / 2, (x + this.squaresDown) * Tile.TileSpriteHeight / 2) + adjust, | ||||
Color.White, 0.81f); | ||||
r12 | ||||
r462 | } | |||
r46 | } | |||
r526 | batch.End(); | |||
r514 | stopWatch2.Stop(); | |||
this.gridDrawTime = stopWatch2.Elapsed; | ||||
r462 | #endregion draw_gridlines | |||
r1 | ||||
r34 | ||||
r462 | //Gridlines | |||
//Lines going down and to the right: | ||||
/* | ||||
for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++) | ||||
{ | ||||
int rowOffset = 0; | ||||
r12 | ||||
r462 | float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2); | |||
r1 | ||||
r462 | Vector2 start = new Vector2(startX, -baseOffsetY+4); | |||
Vector2 stop = new Vector2(startX + this.squaresAcross* Tile.TileStepX/2, | ||||
this.squaresDown*Tile.TileStepY- baseOffsetY+4); | ||||
r1 | ||||
r12 | ||||
r8 | ||||
r462 | Line.drawLine(batch, | |||
Line.departurePoint(stop, start, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), | ||||
Line.departurePoint(start, stop, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), | ||||
Color.White, 0.8f); | ||||
r1 | ||||
r462 | } | |||
//Lines going down and to the left: | ||||
for (int x = 0; x < (int)(1.5*this.squaresAcross); x++) | ||||
{ | ||||
r12 | ||||
r462 | float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2); | |||
r1 | ||||
r462 | Vector2 start_reverse = new Vector2(startX, -baseOffsetY + 4); | |||
Vector2 stop_reverse = new Vector2(startX + -(this.squaresAcross * Tile.TileStepX / 2), | ||||
(this.squaresDown * Tile.TileStepY) - baseOffsetY + 4); | ||||
r1 | ||||
r462 | Line.drawLine(batch, | |||
Line.departurePoint(stop_reverse, start_reverse, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), | ||||
Line.departurePoint(start_reverse, stop_reverse, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), | ||||
Color.White, 0.8f); | ||||
r2 | ||||
r462 | } | |||
*/ | ||||
r527 | tileBatch.Begin(SpriteSortMode.BackToFront, | |||
r534 | BlendState.AlphaBlend, | |||
null, | ||||
null, | ||||
null, | ||||
null, | ||||
camera.get_transformation(GraphicsDevice)); | ||||
r47 | ||||
r48 | #if DEBUG | |||
r462 | drawTileAt(4, 4, 140, 3); | |||
drawTileAt(6, 4, 141, 3); | ||||
drawTileAt(8, 4, 142, 2); | ||||
drawTileAt(10, 4, 142, 3); | ||||
#endif | ||||
r154 | ||||
r462 | #region draw_cursor | |||
if (MathUtils.Between(this.mouseGrid.X, 0, this.simulation.map.MapWidth) | ||||
&& MathUtils.Between(this.mouseGrid.Y, 0, this.simulation.map.MapHeight)) | ||||
{ | ||||
r527 | Tile.OutlineSquare(tileBatch, this.mouseGrid.X, this.mouseGrid.Y, Color.Yellow, 1); | |||
r462 | } | |||
r153 | ||||
r462 | #if DEBUG | |||
r527 | Tile.OutlineSquare(tileBatch, 1, 1, Color.Red, 2); | |||
Tile.OutlineSquare(tileBatch, 3, 1, Color.Blue, 2); | ||||
Tile.OutlineSquare(tileBatch, 5, 1, Color.Green, 2); | ||||
Tile.OutlineSquare(tileBatch, 7, 1, Color.Orange, 2); | ||||
Tile.OutlineSquare(tileBatch, 9, 1, Color.Orange, 3); | ||||
r206 | ||||
r462 | //donut | |||
r527 | Tile.DrawOutlinedSquares(tileBatch, new Vector2[] {new Vector2(19, 1), new Vector2(19, 2), new Vector2(20, 1), new Vector2(21, 1), | |||
r462 | new Vector2(21, 2), new Vector2(19, 3), new Vector2(20, 3), new Vector2(21, 3) | |||
}, Color.Purple); | ||||
r527 | Quad.FillSquare2(tileBatch, 7, 4, Color.Orange, 1.0f, 0.79f); | |||
Quad.FillSquare2(tileBatch, 7, 3, Color.Yellow, 1.0f, 0.79f); | ||||
Quad.FillSquare2(tileBatch, 7, 5, Color.Yellow, .5f, 0.79f); | ||||
Quad.FillSquare2(tileBatch, 7, 6, Color.Yellow, .25f, 0.79f); | ||||
Quad.FillSquare2(tileBatch, 7, 7, Color.Yellow, .125f, 0.79f); | ||||
Quad.FillSquare2(tileBatch, 8, 5, Color.Teal, .5f, 0.79f); | ||||
Quad.FillSquare2(tileBatch, 8, 6, Color.Teal, .25f, 0.79f); | ||||
Quad.FillSquare2(tileBatch, 8, 7, Color.Teal, .125f, 0.79f); | ||||
r348 | #endif | |||
r46 | ||||
r462 | #endregion draw_cursor | |||
r4 | ||||
r514 | stopWatch2 = new Stopwatch(); | |||
stopWatch2.Start(); | ||||
r462 | #region draw_trees | |||
if (this.showTrees) { | ||||
for (int i = 0; i < this.simulation.map.MapHeight; i++) | ||||
r152 | { | |||
r462 | for (int j = 0; j < this.simulation.map.MapWidth; j += 1) | |||
{ | ||||
r522 | if (this.simulation.map.cells[i][j].HasTree) | |||
r462 | { //until we actually simulate: | |||
r521 | if (this.simulation.map.cells[i][j].Type == TreeType.GenericDeciduous) { | |||
r529 | drawTileAt(i, j, 252, 2); // 142, , 262 | |||
} | ||||
else if (this.simulation.map.cells[i][j].Type == TreeType.Oak) { | ||||
drawTileAt(i, j, 142, 2); | ||||
} | ||||
else if (this.simulation.map.cells[i][j].Type == TreeType.GenericShrub) { | ||||
drawTileAt(i, j, 210, 2); | ||||
r520 | } | |||
else { | ||||
r534 | drawTileAt(i, j, 122, 2); //122, 203, 221 | |||
r520 | } | |||
r462 | // if ((i + j) % 8 == 0) | |||
// { | ||||
// drawTileAt(i, j, 141, 2); | ||||
// } | ||||
// else | ||||
// { | ||||
// drawTileAt(i, j, 142, 2); | ||||
// } | ||||
} | ||||
r522 | else if (this.simulation.map.cells[i][j].Status == CellStatus.DeadTree) { | |||
r462 | drawTileAt(i, j, 141, 2); | |||
// System.Console.WriteLine(String.Format("Drew Dead Tree at {0},{1}", i, j)); | ||||
} | ||||
r152 | } | |||
r101 | } | |||
r46 | } | |||
r514 | stopWatch2.Stop(); | |||
this.treeDrawTime = stopWatch2.Elapsed; | ||||
r462 | #endregion draw_trees | |||
r9 | ||||
r199 | #if DEBUG | |||
r462 | drawTileAt(2, 2, 140, 2); | |||
drawTileAt(1, 1, 140, 2); | ||||
drawTileAt(3, 2, 140, 2); | ||||
r199 | #endif | |||
r9 | ||||
r462 | World.Draw(); | |||
// _imGuiRenderer.AfterLayout(); | ||||
r527 | tileBatch.End(); | |||
r4 | ||||
r462 | #region draw_header | |||
batch.Begin(SpriteSortMode.BackToFront, | ||||
BlendState.AlphaBlend, | ||||
null, | ||||
null, | ||||
null, | ||||
null); | ||||
r4 | ||||
r481 | if (MathUtils.BetweenExclusive(this.mouseGrid.X, 0, this.squaresAcross) | |||
&& MathUtils.BetweenExclusive(this.mouseGrid.Y, 0, this.squaresAcross)) | ||||
r462 | { | |||
r522 | has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].HasTree; | |||
r462 | } | |||
r17 | ||||
r462 | String status_left = ""; | |||
r481 | if (MathUtils.BetweenExclusive(this.mouseGrid.X, -1, this.simulation.map.MapWidth) | |||
&& MathUtils.BetweenExclusive(this.mouseGrid.Y, -1, this.simulation.map.MapHeight)) | ||||
r462 | { | |||
r522 | var treeStatus = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].Status; | |||
r521 | var treeStatusAdjective = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].StatusAdjective; | |||
var treeType = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].TypeName; | ||||
r541 | var useStatus = this.CurrentStatus(); | |||
r521 | if (treeStatus != CellStatus.Clear) | |||
{ | ||||
status_left = String.Format("{0:},{1:} {2} {3} ({4})", this.mouseGrid.X, this.mouseGrid.Y, | ||||
r534 | treeStatusAdjective, | |||
treeType, | ||||
r541 | useStatus); | |||
r521 | } | |||
else { | ||||
status_left = String.Format("{0:},{1:} {2} ({3})", this.mouseGrid.X, this.mouseGrid.Y, | ||||
r534 | treeStatusAdjective, | |||
r541 | useStatus); | |||
r521 | } | |||
r462 | } | |||
r17 | ||||
r462 | String header_left = String.Format("${0:}|{1:} \ue124", this.simulation.money, this.simulation.map.tree_count); | |||
String header_middle = String.Format("{0:MMMMM yyyy} ({1:})", this.simulation.DateTime, this.simulation.Season); | ||||
// String header_right = String.Format("Press H for help."); | ||||
String header_right = ""; | ||||
r46 | ||||
r462 | this.Window.Title = String.Format("Isometric Park [{0:}]", header_middle); | |||
Vector2 middle_dimensions = monoFont.MeasureString(header_middle); | ||||
Vector2 right_dimensions = monoFont.MeasureString(header_right); | ||||
r46 | ||||
r462 | float middle_start = (int)((FNAGame.width / 2) - (middle_dimensions.X / 2)); | |||
float right_start = (int)(FNAGame.width - right_dimensions.X - 10.0f); | ||||
float top = (float)Math.Round(FNAGame.height - middle_dimensions.Y); // Rounding so the int and float versions are closer. | ||||
r46 | ||||
r462 | FilledRectangle.drawFilledRectangle(batch, new Rectangle(0, (int)top, width, (int)middle_dimensions.Y), Color.White, 0.51f); | |||
r46 | ||||
r462 | batch.DrawString(monoFont, status_left, new Vector2(1, top), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); | |||
batch.DrawString(monoFont, header_left, new Vector2(1, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); | ||||
batch.DrawString(monoFont, header_middle, new Vector2(middle_start, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); | ||||
#endregion draw_header | ||||
r14 | ||||
r462 | #region budget | |||
r52 | ||||
r462 | if (this.showBudget) | |||
{ | ||||
budgetWindow.draw(batch); | ||||
} | ||||
r52 | ||||
r462 | #endregion budget | |||
r52 | ||||
r462 | batch.End(); | |||
r4 | ||||
r462 | #region window | |||
Menu.Render(debugWindow.monoFont, FNAGame.width, this.imGuiWindowBridgeEngine, ref quit, ref this.simulation.paused, ref this.simulation.currentRate, ref this.showBudget, header_left); | ||||
r297 | ||||
r462 | if (quit) { | |||
System.Environment.Exit(0); | ||||
} | ||||
r297 | ||||
r462 | } | |||
else { | ||||
GraphicsDevice.Clear(Color.Teal); | ||||
batch.Begin(SpriteSortMode.BackToFront, | ||||
BlendState.AlphaBlend, | ||||
null, | ||||
null, | ||||
null, | ||||
null); | ||||
r297 | ||||
r462 | Vector2 middle_dimensions = largeMonoFont.MeasureString("Isometric Park"); | |||
float middle_start = (int)((FNAGame.width / 2) - (middle_dimensions.X / 2)); | ||||
batch.DrawString(largeMonoFont, "Isometric Park", | ||||
new Vector2(middle_start, 50), | ||||
Color.Black, 0.0f, Vector2.Zero, | ||||
1.0f, SpriteEffects.None, 0.5f); | ||||
batch.DrawString(largeMonoFont, "Isometric Park", | ||||
new Vector2(middle_start-1, 49), | ||||
Color.White, 0.0f, Vector2.Zero, | ||||
1.0f, SpriteEffects.None, 0.51f); | ||||
World.Draw(); | ||||
r299 | ||||
r462 | Vector2 version_dimensions = monoFont.MeasureString(typeof(FNAGame).Assembly.GetName().Version.ToString()); | |||
batch.DrawString(monoFont, | ||||
typeof(FNAGame).Assembly.GetName().Version.ToString(), | ||||
new Vector2(0, FNAGame.height-version_dimensions.Y), | ||||
Color.White, 0.0f, Vector2.Zero, | ||||
1.0f, SpriteEffects.None, 0.51f); | ||||
r300 | ||||
r462 | Vector2 name_dimensions = monoFont.MeasureString("by actuallyalys<3"); | |||
float name_start = (int)(FNAGame.width / 2) - (name_dimensions.X / 2); | ||||
r300 | ||||
r462 | batch.DrawString(monoFont, "by actuallyalys <3", | |||
new Vector2(name_start, 50+middle_dimensions.Y), | ||||
Color.White, 0.0f, Vector2.Zero, | ||||
1.0f, SpriteEffects.None, 0.51f); | ||||
batch.End(); | ||||
} | ||||
#endregion | ||||
r297 | ||||
r4 | ||||
r462 | #region debug_window | |||
r46 | //Calcs for debug window: | |||
r518 | past_draw.Enqueue(this.drawTime); | |||
r46 | if ((this.frameCounter % 15) == 0) | |||
{ | ||||
past_fps.Enqueue(this.frameRate); | ||||
r16 | ||||
r518 | ||||
r462 | /* | |||
r481 | if (this.frameRate > 60.0) | |||
{ | ||||
Logging.Warning(String.Format("Framerate is higher than limit: {0}", this.frameRate)); | ||||
} | ||||
if (this.frameRate < 30.0) | ||||
{ | ||||
Logging.Warning(String.Format("Framerate is lower than desired: {0}", this.frameRate)); | ||||
} | ||||
*/ | ||||
r46 | } | |||
r246 | /* | |||
if (this.frameRate > 120.0) | ||||
{ | ||||
Logging.Error(String.Format("Framerate is much higher than limit: {0}", this.frameRate)); | ||||
} | ||||
else if (this.frameRate < 15.0) | ||||
{ | ||||
Logging.Error(String.Format("Framerate is much lower than desired: {0}", this.frameRate)); | ||||
} | ||||
*/ | ||||
r46 | DebugInfo debugInfo = new DebugInfo | |||
r462 | { fps = this.frameRate, | |||
r46 | pastFps = past_fps.ToArray(), | |||
cameraPosition = camera.position, | ||||
drawTime = this.drawTime, | ||||
r514 | treeDrawTime = this.treeDrawTime, | |||
gridDrawTime = this.gridDrawTime, | ||||
tileDrawTime = this.tileDrawTime, | ||||
r101 | updateTime = this.updateTime, | |||
r46 | treeCount = this.simulation.map.tree_count, | |||
mouseGrid = this.mouseGrid, | ||||
hasTree = has_tree, | ||||
tilesDrawn = this.tilesDrawn | ||||
}; | ||||
r33 | ||||
r46 | //Finally, draw the debug window | |||
r33 | ||||
r46 | var additionalInfo = new Dictionary<string, string>(); | |||
r16 | ||||
r101 | Vector2 cameraMiddle = this.camera.position + new Vector2(FNAGame.width / 2, FNAGame.height / 2); | |||
var state = Mouse.GetState(); | ||||
Vector2 delta = this.camera.position - this.original_point; | ||||
r48 | ||||
r101 | additionalInfo.Add("cameraMiddle", cameraMiddle.ToString()); | |||
additionalInfo.Add("mouse ", String.Format("{0}, {1}", state.X, state.Y)); | ||||
additionalInfo.Add("mouse delta", delta.ToString()); | ||||
r48 | ||||
r429 | string entries = ""; | |||
r443 | string descriptions = ""; | |||
r429 | foreach (var pair in DialogSpawner.indexes) | |||
{ | ||||
r443 | entries += String.Format("{0}={1},", pair.Key, pair.Value); | |||
} | ||||
foreach (var meta in portraitsMap.Metadata) | ||||
{ | ||||
r462 | descriptions += String.Format("{0}: {1}\n", meta.Filename, | |||
meta.Description); | ||||
r429 | } | |||
r101 | additionalInfo.Add("Tracery Test", this.output); | |||
r281 | additionalInfo.Add("Log Entry", string.Format("{0} {1}", Logging.entries[Logging.entries.Count-1].level, Logging.entries[Logging.entries.Count-1].message)); | |||
r462 | additionalInfo.Add("Dialog entries", entries); | |||
additionalInfo.Add("Metadata entries", descriptions); | ||||
r51 | ||||
r518 | if (past_fps.Count() > 5) { | |||
additionalInfo.Add(".01%% fps", MathUtils.Percentile(past_fps.Skip(5).ToArray(), 0.0001f).ToString()); | ||||
additionalInfo.Add(".1%% fps", MathUtils.Percentile(past_fps.Skip(5).ToArray(), 0.001f).ToString()); | ||||
additionalInfo.Add("1%% fps", MathUtils.Percentile(past_fps.Skip(5).ToArray(), 0.01f).ToString()); | ||||
additionalInfo.Add("50%% fps", MathUtils.Percentile(past_fps.Skip(5).ToArray(), 0.50f).ToString()); | ||||
} | ||||
if (past_draw.Count() > 5) { | ||||
var past_draw_floats = past_draw.Skip(5).Select(ts => ts.TotalMilliseconds).ToArray(); | ||||
additionalInfo.Add(".01%% draw", MathUtils.Percentile(past_draw_floats, 0.0001f).ToString()); | ||||
additionalInfo.Add(".1%% draw", MathUtils.Percentile(past_draw_floats, 0.001f).ToString()); | ||||
additionalInfo.Add("1%% draw", MathUtils.Percentile(past_draw_floats, 0.01f).ToString()); | ||||
additionalInfo.Add("50%% draw", MathUtils.Percentile(past_draw_floats, 0.50f).ToString()); | ||||
additionalInfo.Add("99%% draw", MathUtils.Percentile(past_draw_floats, 0.99f).ToString()); | ||||
additionalInfo.Add("99.9%% draw", MathUtils.Percentile(past_draw_floats, 0.999f).ToString()); | ||||
additionalInfo.Add("99.99%% draw", MathUtils.Percentile(past_draw_floats, 0.9999f).ToString()); | ||||
} | ||||
r101 | debugWindow.Layout(debugInfo, additionalInfo, ref show_another_window); | |||
r18 | ||||
r46 | _imGuiRenderer.AfterLayout(); | |||
r34 | ||||
r462 | #endregion debug_window | |||
r16 | ||||
r34 | stopWatch.Stop(); | |||
r46 | this.drawTime = stopWatch.Elapsed; | |||
base.Draw(gameTime); | ||||
} | ||||
r307 | ||||
r310 | public void setResolution(Vector2 newResolution, bool fullscreen) | |||
r307 | { | |||
r348 | FNAGame.width = (int)newResolution.X; | |||
FNAGame.height = (int)newResolution.Y; | ||||
r307 | ||||
r348 | this.gdm.PreferredBackBufferWidth = (int)newResolution.X; | |||
this.gdm.PreferredBackBufferHeight = (int)newResolution.Y; | ||||
this.gdm.IsFullScreen = fullscreen; | ||||
this.gdm.ApplyChanges(); | ||||
r307 | } | |||
r11 | } | |||