GraphDraw.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GraphDraw.cpp ////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Aug 2002
  34. //
  35. // Filename: GraphDraw.cpp
  36. //
  37. // author: John McDonald
  38. //
  39. // purpose: Contains the functions to queue up and display a single graph for
  40. // each frame
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #include "PreRTS.h"
  45. #include "GameClient/GraphDraw.h"
  46. #include "GameClient/Display.h"
  47. #include "GameClient/DisplayString.h"
  48. #include "GameClient/DisplayStringManager.h"
  49. #ifdef PERF_TIMERS
  50. //-------------------------------------------------------------------------------------------------
  51. GraphDraw::GraphDraw()
  52. {
  53. for (Int i = 0; i < MAX_GRAPH_VALUES; ++i) {
  54. m_displayStrings[i] = TheDisplayStringManager->newDisplayString();
  55. m_displayStrings[i]->setFont(TheFontLibrary->getFont("Courier", 10, false));
  56. }
  57. }
  58. //-------------------------------------------------------------------------------------------------
  59. GraphDraw::~GraphDraw()
  60. {
  61. for (Int i = 0; i < MAX_GRAPH_VALUES; ++i) {
  62. TheDisplayStringManager->freeDisplayString(m_displayStrings[i]);
  63. }
  64. }
  65. //-------------------------------------------------------------------------------------------------
  66. void GraphDraw::addEntry(AsciiString str, Real val)
  67. {
  68. m_graphEntries.push_back(std::make_pair(str, val));
  69. }
  70. //-------------------------------------------------------------------------------------------------
  71. void GraphDraw::render()
  72. {
  73. Int width = TheDisplay->getWidth();
  74. // divide the width by two because we're going to use the left half of the screen for labels.
  75. //width /= 2;
  76. // give more to bars than labels. (srj)
  77. Int start = width * 0.33f;
  78. width -= start;
  79. Int height = TheDisplay->getHeight();
  80. Int totalCount = m_graphEntries.size();
  81. DEBUG_ASSERTCRASH(totalCount < MAX_GRAPH_VALUES, ("MAX_GRAPH_VALUES must be increased, not all labels will appear (max %d, cur %d).\n",MAX_GRAPH_VALUES,totalCount));
  82. DEBUG_ASSERTCRASH(BAR_HEIGHT * totalCount < height, ("BAR_HEIGHT must be reduced, as bars are being drawn off-screen.\n"));
  83. VecGraphEntriesIt it;
  84. Int count = 0;
  85. for (it = m_graphEntries.begin(); it != m_graphEntries.end(); ++it) {
  86. if (count < MAX_GRAPH_VALUES) {
  87. // draw the label.
  88. UnicodeString uniStr;
  89. uniStr.translate(it->first);
  90. m_displayStrings[count]->setText(uniStr);
  91. m_displayStrings[count]->draw(5, count * BAR_HEIGHT, 0xFFFFFFFF, 0x00000000, 1, 1);
  92. }
  93. TheDisplay->drawFillRect(start, count * BAR_HEIGHT - (BAR_SPACE / 2), it->second / 100000.0f * width, BAR_HEIGHT - BAR_SPACE, 0x7FFFFFFF);
  94. ++count;
  95. }
  96. }
  97. //-------------------------------------------------------------------------------------------------
  98. void GraphDraw::clear()
  99. {
  100. m_graphEntries.clear();
  101. }
  102. GraphDraw *TheGraphDraw = NULL;
  103. #endif /* PERF_TIMERS */