debugging.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <stdio.h>
  14. #include <string.h>
  15. #include <GameOS\GameOS.hpp>
  16. #include <GameOS\ToolOS.hpp>
  17. HGOSFONT3D GameDebugWindow::font = NULL;
  18. long GameDebugWindow::fontHeight = 0;
  19. //***************************************************************************
  20. // GAME DEBUG WINDOW class
  21. //***************************************************************************
  22. void GameDebugWindow::setFont (char* fontFile) {
  23. if (font) {
  24. gos_DeleteFont(font);
  25. font = NULL;
  26. }
  27. if (fontFile) {
  28. font = gos_LoadFont(fontFile);
  29. gos_TextSetAttributes(font, 0xffffffff, 1.0, true, true, false, false);
  30. }
  31. DWORD height, width;
  32. gos_TextStringLength(&width, &height, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  33. fontHeight = height;
  34. }
  35. //---------------------------------------------------------------------------
  36. void GameDebugWindow::print (char* s) {
  37. if (numLines < MAX_DEBUG_WINDOW_LINES)
  38. strcpy(textBuffer[numLines++], s);
  39. else {
  40. numLines++;
  41. strcpy(textBuffer[linePos++], s);
  42. if (linePos == MAX_DEBUG_WINDOW_LINES)
  43. linePos = 0;
  44. }
  45. }
  46. //---------------------------------------------------------------------------
  47. void GameDebugWindow::render (void) {
  48. if (!display)
  49. return;
  50. long curY = pos[1] + 5;
  51. for (long i = linePos; i < MAX_DEBUG_WINDOW_LINES; i++) {
  52. gos_TextSetPosition(pos[0] + 5, curY);
  53. curY += fontHeight;
  54. gos_TextDraw(textBuffer[i]);
  55. }
  56. for (i = 0; i < linePos; i++) {
  57. gos_TextSetPosition(pos[0] + 5, curY);
  58. curY += fontHeight;
  59. gos_TextDraw(textBuffer[i]);
  60. }
  61. }
  62. //***************************************************************************