Description:
Add rudimentary (disabled) culling.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -19,6 +19,7 | |||
|
19 | 19 | public int treeCount; |
|
20 | 20 | public Vector2 mouseGrid; |
|
21 | 21 | public Boolean hasTree; |
|
22 | public int tilesDrawn; | |
|
22 | 23 | |
|
23 | 24 | } |
|
24 | 25 | |
@@ -101,13 +102,15 | |||
|
101 | 102 | public virtual void Layout(DebugInfo debugInfo, Dictionary<String, String> additionalInfo, ref bool show) |
|
102 | 103 | { |
|
103 | 104 | |
|
104 | if (show) | |
|
105 | { | |
|
105 | if (show) | |
|
106 | { | |
|
106 | 107 | ImGui.Begin("Debug", ref show); |
|
107 | 108 | ImGui.Text(string.Format("fps: {0:F3}", debugInfo.fps)); |
|
108 | 109 | ImGui.Text(string.Format("Draw Time: {0:F3}", debugInfo.drawTime.TotalMilliseconds.ToString())); |
|
110 | ImGui.Text(string.Format("Tiles Drawn: {0:F}", debugInfo.tilesDrawn)); | |
|
109 | 111 | |
|
110 | ImGui.Text(string.Format("\nCamera Position: {0}", debugInfo.cameraPosition.ToString())); | |
|
112 | ||
|
113 | ImGui.Text(string.Format("\nCamera Position: {0}", debugInfo.cameraPosition.ToString())); | |
|
111 | 114 | ImGui.Text(string.Format("\nGrid Position: {0} (has tree: {1})", debugInfo.mouseGrid.ToString(), debugInfo.hasTree)); |
|
112 | 115 | |
|
113 | 116 | ImGui.Text(string.Format("Application average {0:F3} ms/frame ({1:F1} FPS", 1000f / ImGui.GetIO().Framerate, ImGui.GetIO().Framerate)); |
@@ -35,6 +35,7 | |||
|
35 | 35 | TimeSpan elapsedTime = TimeSpan.Zero; |
|
36 | 36 | TimeSpan drawTime = TimeSpan.Zero; |
|
37 | 37 | Queue<float> past_fps = new Queue<float>(100); |
|
38 | int tilesDrawn = 0; | |
|
38 | 39 | |
|
39 | 40 | private const int width = 1280; |
|
40 | 41 | private const int height = 640; |
@@ -48,8 +49,8 | |||
|
48 | 49 | private int aiScore = 0; |
|
49 | 50 | |
|
50 | 51 | //new tile stuff |
|
51 | int squaresAcross = 50; | |
|
52 | int squaresDown = 50; | |
|
52 | int squaresAcross = 150; | |
|
53 | int squaresDown = 150; | |
|
53 | 54 | int baseOffsetX = -14; |
|
54 | 55 | int baseOffsetY = -14; |
|
55 | 56 | |
@@ -67,7 +68,10 | |||
|
67 | 68 | private bool showInitial; |
|
68 | 69 | int messageIndex; |
|
69 | 70 | |
|
70 | private static void Main(string[] args) | |
|
71 | //buggy | |
|
72 | private static bool enableCulling = true; | |
|
73 | ||
|
74 | private static void Main(string[] args) | |
|
71 | 75 | { |
|
72 | 76 | using FNAGame g = new FNAGame(); |
|
73 | 77 | g.Run(); |
@@ -381,6 +385,18 | |||
|
381 | 385 | drawTileAt(x, y, tileIndex, height, depthOffset); |
|
382 | 386 | } |
|
383 | 387 | |
|
388 | protected Boolean cull(int gridX, int gridY) | |
|
389 | { | |
|
390 | int screenX = (gridX - gridY) * Tile.TileSpriteWidth / 2; | |
|
391 | int screenY = (gridX + gridY) * Tile.TileSpriteHeight / 2; | |
|
392 | ||
|
393 | Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice)); | |
|
394 | ||
|
395 | return (!FNAGame.enableCulling || | |
|
396 | (MathUtils.Between(original.X, -Tile.TileSpriteWidth, FNAGame.width) | |
|
397 | && MathUtils.Between(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); | |
|
398 | } | |
|
399 | ||
|
384 | 400 | protected void drawTileAt(int x, int y, int tileIndex, int height, float depth) |
|
385 | 401 | { |
|
386 | 402 | /* |
@@ -429,7 +445,9 | |||
|
429 | 445 | int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2; |
|
430 | 446 | int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2; |
|
431 | 447 | |
|
432 | batch.Draw( | |
|
448 | if (this.cull(x, y)) | |
|
449 | { | |
|
450 | batch.Draw( | |
|
433 | 451 | Tile.TileSetTexture, |
|
434 | 452 | new Rectangle( |
|
435 | 453 | screenx, |
@@ -441,6 +459,8 | |||
|
441 | 459 | Vector2.Zero, |
|
442 | 460 | SpriteEffects.None, |
|
443 | 461 | depth); |
|
462 | } | |
|
463 | ||
|
444 | 464 | } |
|
445 | 465 | |
|
446 | 466 | |
@@ -507,7 +527,8 | |||
|
507 | 527 | }*/ |
|
508 | 528 | |
|
509 | 529 | |
|
510 | ||
|
530 | //reset | |
|
531 | this.tilesDrawn = 0; | |
|
511 | 532 | |
|
512 | 533 | for (int y = 0; y < this.squaresDown; y++) |
|
513 | 534 | { |
@@ -519,7 +540,8 | |||
|
519 | 540 | |
|
520 | 541 | int screeny = (x + y) * Tile.TileSpriteHeight / 2; |
|
521 | 542 | |
|
522 | batch.Draw( | |
|
543 | if (this.cull(x, y)) { | |
|
544 | batch.Draw( | |
|
523 | 545 | Tile.TileSetTexture, |
|
524 | 546 | new Rectangle( |
|
525 | 547 | screenx, |
@@ -531,6 +553,11 | |||
|
531 | 553 | Vector2.Zero, |
|
532 | 554 | SpriteEffects.None, |
|
533 | 555 | 0.9f); |
|
556 | ||
|
557 | this.tilesDrawn++; | |
|
558 | } | |
|
559 | ||
|
560 | ||
|
534 | 561 | } |
|
535 | 562 | |
|
536 | 563 | } |
@@ -698,14 +725,14 | |||
|
698 | 725 | drawTime = this.drawTime, |
|
699 | 726 | treeCount = this.map.tree_count, |
|
700 | 727 | mouseGrid = this.mouseGrid, |
|
701 | hasTree = has_tree | |
|
728 | hasTree = has_tree, | |
|
729 | tilesDrawn = this.tilesDrawn | |
|
702 | 730 | }; |
|
703 | 731 | |
|
704 | 732 | //Finally, draw the debug window |
|
705 | 733 | _imGuiRenderer.BeforeLayout(gameTime); |
|
706 | 734 | debugWindow.Layout(debugInfo, new Dictionary<string, string>(),ref show_another_window); |
|
707 | 735 | |
|
708 | ||
|
709 | 736 | String[] messages = { "Message1", "Message2" }; |
|
710 | 737 | |
|
711 | 738 | if (showInitial && (messageIndex < messages.Length)) |
@@ -719,7 +746,6 | |||
|
719 | 746 | } |
|
720 | 747 | |
|
721 | 748 | ImGui.PopFont(); |
|
722 | ||
|
723 | 749 | } |
|
724 | 750 | |
|
725 | 751 | _imGuiRenderer.AfterLayout(); |
You need to be logged in to leave comments.
Login now