Description:
Add rudimentary (disabled) culling.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r19:84e8a1e7b6ca -

1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,1 +1,1
1 3bfc026cc1a44062c5e5753272a43f3f886b3132
1 eb53a31a465d1700585a27323fb9618e935e3337
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -19,6 +19,7
19 public int treeCount;
19 public int treeCount;
20 public Vector2 mouseGrid;
20 public Vector2 mouseGrid;
21 public Boolean hasTree;
21 public Boolean hasTree;
22 public int tilesDrawn;
22
23
23 }
24 }
24
25
@@ -101,13 +102,15
101 public virtual void Layout(DebugInfo debugInfo, Dictionary<String, String> additionalInfo, ref bool show)
102 public virtual void Layout(DebugInfo debugInfo, Dictionary<String, String> additionalInfo, ref bool show)
102 {
103 {
103
104
104 if (show)
105 if (show)
105 {
106 {
106 ImGui.Begin("Debug", ref show);
107 ImGui.Begin("Debug", ref show);
107 ImGui.Text(string.Format("fps: {0:F3}", debugInfo.fps));
108 ImGui.Text(string.Format("fps: {0:F3}", debugInfo.fps));
108 ImGui.Text(string.Format("Draw Time: {0:F3}", debugInfo.drawTime.TotalMilliseconds.ToString()));
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 ImGui.Text(string.Format("\nGrid Position: {0} (has tree: {1})", debugInfo.mouseGrid.ToString(), debugInfo.hasTree));
114 ImGui.Text(string.Format("\nGrid Position: {0} (has tree: {1})", debugInfo.mouseGrid.ToString(), debugInfo.hasTree));
112
115
113 ImGui.Text(string.Format("Application average {0:F3} ms/frame ({1:F1} FPS", 1000f / ImGui.GetIO().Framerate, ImGui.GetIO().Framerate));
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 TimeSpan elapsedTime = TimeSpan.Zero;
35 TimeSpan elapsedTime = TimeSpan.Zero;
36 TimeSpan drawTime = TimeSpan.Zero;
36 TimeSpan drawTime = TimeSpan.Zero;
37 Queue<float> past_fps = new Queue<float>(100);
37 Queue<float> past_fps = new Queue<float>(100);
38 int tilesDrawn = 0;
38
39
39 private const int width = 1280;
40 private const int width = 1280;
40 private const int height = 640;
41 private const int height = 640;
@@ -48,8 +49,8
48 private int aiScore = 0;
49 private int aiScore = 0;
49
50
50 //new tile stuff
51 //new tile stuff
51 int squaresAcross = 50;
52 int squaresAcross = 150;
52 int squaresDown = 50;
53 int squaresDown = 150;
53 int baseOffsetX = -14;
54 int baseOffsetX = -14;
54 int baseOffsetY = -14;
55 int baseOffsetY = -14;
55
56
@@ -67,7 +68,10
67 private bool showInitial;
68 private bool showInitial;
68 int messageIndex;
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 using FNAGame g = new FNAGame();
76 using FNAGame g = new FNAGame();
73 g.Run();
77 g.Run();
@@ -381,6 +385,18
381 drawTileAt(x, y, tileIndex, height, depthOffset);
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 protected void drawTileAt(int x, int y, int tileIndex, int height, float depth)
400 protected void drawTileAt(int x, int y, int tileIndex, int height, float depth)
385 {
401 {
386 /*
402 /*
@@ -429,7 +445,9
429 int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2;
445 int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2;
430 int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2;
446 int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2;
431
447
432 batch.Draw(
448 if (this.cull(x, y))
449 {
450 batch.Draw(
433 Tile.TileSetTexture,
451 Tile.TileSetTexture,
434 new Rectangle(
452 new Rectangle(
435 screenx,
453 screenx,
@@ -441,6 +459,8
441 Vector2.Zero,
459 Vector2.Zero,
442 SpriteEffects.None,
460 SpriteEffects.None,
443 depth);
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 for (int y = 0; y < this.squaresDown; y++)
533 for (int y = 0; y < this.squaresDown; y++)
513 {
534 {
@@ -519,7 +540,8
519
540
520 int screeny = (x + y) * Tile.TileSpriteHeight / 2;
541 int screeny = (x + y) * Tile.TileSpriteHeight / 2;
521
542
522 batch.Draw(
543 if (this.cull(x, y)) {
544 batch.Draw(
523 Tile.TileSetTexture,
545 Tile.TileSetTexture,
524 new Rectangle(
546 new Rectangle(
525 screenx,
547 screenx,
@@ -531,6 +553,11
531 Vector2.Zero,
553 Vector2.Zero,
532 SpriteEffects.None,
554 SpriteEffects.None,
533 0.9f);
555 0.9f);
556
557 this.tilesDrawn++;
558 }
559
560
534 }
561 }
535
562
536 }
563 }
@@ -698,14 +725,14
698 drawTime = this.drawTime,
725 drawTime = this.drawTime,
699 treeCount = this.map.tree_count,
726 treeCount = this.map.tree_count,
700 mouseGrid = this.mouseGrid,
727 mouseGrid = this.mouseGrid,
701 hasTree = has_tree
728 hasTree = has_tree,
729 tilesDrawn = this.tilesDrawn
702 };
730 };
703
731
704 //Finally, draw the debug window
732 //Finally, draw the debug window
705 _imGuiRenderer.BeforeLayout(gameTime);
733 _imGuiRenderer.BeforeLayout(gameTime);
706 debugWindow.Layout(debugInfo, new Dictionary<string, string>(),ref show_another_window);
734 debugWindow.Layout(debugInfo, new Dictionary<string, string>(),ref show_another_window);
707
735
708
709 String[] messages = { "Message1", "Message2" };
736 String[] messages = { "Message1", "Message2" };
710
737
711 if (showInitial && (messageIndex < messages.Length))
738 if (showInitial && (messageIndex < messages.Length))
@@ -719,7 +746,6
719 }
746 }
720
747
721 ImGui.PopFont();
748 ImGui.PopFont();
722
723 }
749 }
724
750
725 _imGuiRenderer.AfterLayout();
751 _imGuiRenderer.AfterLayout();
You need to be logged in to leave comments. Login now