color.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //******************************************************************************************
  2. // color.cpp - This file contains the code for the Color Tables
  3. //
  4. // MechCommander 2
  5. //
  6. //---------------------------------------------------------------------------//
  7. // Copyright (C) Microsoft Corporation. All rights reserved. //
  8. //===========================================================================//
  9. #ifndef COLOR_H
  10. #include "color.h"
  11. #endif
  12. #ifndef PATHS_H
  13. #include "paths.h"
  14. #endif
  15. #ifndef CIDENT_H
  16. #include "cident.h"
  17. #endif
  18. #ifndef INIFILE_H
  19. #include "inifile.h"
  20. #endif
  21. #ifndef HEAP_H
  22. #include "heap.h"
  23. #endif
  24. #include <gameos.hpp>
  25. //----------------------------------------------------------------------------------
  26. DWORD **colorRGBLookup = NULL;
  27. long numColorRGBTables = 0;
  28. #define MAX_COLOR_ENTRIES 56
  29. //----------------------------------------------------------------------------------
  30. void initColorTables (void)
  31. {
  32. FullPathFileName colorPath;
  33. colorPath.init(cameraPath,"colors",".fit");
  34. FitIniFile colorFile;
  35. long result = colorFile.open(colorPath);
  36. gosASSERT(result == NO_ERR);
  37. result = colorFile.seekBlock("Main");
  38. gosASSERT(result == NO_ERR);
  39. result = colorFile.readIdLong("NumTables",numColorRGBTables);
  40. gosASSERT(result == NO_ERR);
  41. colorRGBLookup = (DWORD **)systemHeap->Malloc(sizeof(DWORD *) * numColorRGBTables);
  42. gosASSERT(colorRGBLookup != NULL);
  43. memset(colorRGBLookup,0,sizeof(DWORD *) * numColorRGBTables);
  44. for (long i=0;i<numColorRGBTables;i++)
  45. {
  46. char tableBlock[256];
  47. sprintf(tableBlock,"Table%d",i);
  48. result = colorFile.seekBlock(tableBlock);
  49. gosASSERT(result == NO_ERR);
  50. colorRGBLookup[i] = (DWORD *)systemHeap->Malloc(sizeof(DWORD) * MAX_COLOR_ENTRIES);
  51. gosASSERT(colorRGBLookup[i] != NULL);
  52. DWORD *table = colorRGBLookup[i];
  53. for (long j=0;j<MAX_COLOR_ENTRIES;j++)
  54. {
  55. char colorBlock[256];
  56. sprintf(colorBlock,"Color%d",j);
  57. result = colorFile.readIdULong(colorBlock,table[j]);
  58. gosASSERT(result == NO_ERR);
  59. }
  60. }
  61. colorFile.close();
  62. }
  63. //----------------------------------------------------------------------------------
  64. void destroyColorTables (void)
  65. {
  66. for (long i=0;i<numColorRGBTables;i++)
  67. {
  68. systemHeap->Free(colorRGBLookup[i]);
  69. colorRGBLookup[i] = NULL;
  70. }
  71. if ( colorRGBLookup )
  72. systemHeap->Free(colorRGBLookup);
  73. colorRGBLookup = NULL;
  74. }
  75. //----------------------------------------------------------------------------------
  76. DWORD *getColorTable (long tableNum)
  77. {
  78. if ((tableNum >= 0) && (tableNum < numColorRGBTables))
  79. {
  80. return(colorRGBLookup[tableNum]);
  81. }
  82. return(NULL);
  83. }
  84. //----------------------------------------------------------------------------------