debugging.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //***************************************************************************
  2. //
  3. // Debugging.cpp -- File contains the Game Debugging code
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef DEBUGGING_H
  11. #include "debugging.h"
  12. #endif
  13. #ifndef HEAP_H
  14. #include "heap.h"
  15. #endif
  16. #include <string.h>
  17. extern UserHeapPtr systemHeap;
  18. HGOSFONT3D GameDebugWindow::font = NULL;
  19. long GameDebugWindow::fontHeight = 0;
  20. //***************************************************************************
  21. // GAME DEBUG WINDOW class
  22. //***************************************************************************
  23. void* GameDebugWindow::operator new (size_t ourSize) {
  24. void* result = systemHeap->Malloc(ourSize);
  25. return(result);
  26. }
  27. //---------------------------------------------------------------------------
  28. void GameDebugWindow::operator delete (void* us) {
  29. systemHeap->Free(us);
  30. }
  31. //---------------------------------------------------------------------------
  32. void GameDebugWindow::setFont (char* fontFile) {
  33. if (font) {
  34. gos_DeleteFont(font);
  35. font = NULL;
  36. }
  37. if (fontFile) {
  38. font = gos_LoadFont(fontFile);
  39. gos_TextSetAttributes(font, 0xffffffff, 1.0, true, true, false, false);
  40. }
  41. DWORD height, width;
  42. gos_TextStringLength(&width, &height, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  43. fontHeight = height;
  44. }
  45. //---------------------------------------------------------------------------
  46. void GameDebugWindow::print (char* s) {
  47. if (numLines < MAX_DEBUG_WINDOW_LINES)
  48. strcpy(textBuffer[numLines++], s);
  49. else {
  50. numLines++;
  51. strcpy(textBuffer[linePos++], s);
  52. if (linePos == MAX_DEBUG_WINDOW_LINES)
  53. linePos = 0;
  54. }
  55. }
  56. //---------------------------------------------------------------------------
  57. void GameDebugWindow::render (void) {
  58. if (!display)
  59. return;
  60. gos_TextSetAttributes(font, 0xffffffff, 1.0, true, true, false, false);
  61. gos_TextSetRegion( 0, 0, Environment.screenWidth, Environment.screenHeight );
  62. long curY = pos[1] + 5;
  63. for (long i = linePos; i < MAX_DEBUG_WINDOW_LINES; i++) {
  64. gos_TextSetPosition(pos[0] + 5, curY);
  65. curY += fontHeight;
  66. gos_TextDraw(textBuffer[i]);
  67. }
  68. for (i = 0; i < linePos; i++) {
  69. gos_TextSetPosition(pos[0] + 5, curY);
  70. curY += fontHeight;
  71. gos_TextDraw(textBuffer[i]);
  72. }
  73. }
  74. //***************************************************************************