Advertisement
Faguss

class Grid for Operation Flashpoint

Jun 17th, 2017
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1.  
  2. // Do we want numeric grid?
  3. #define NUM_GRID
  4.  
  5.  
  6.  
  7. // Set options based on which grid was selected
  8. #ifdef NUM_GRID
  9.  
  10.     #define GRID_ZOOMMAX2  1.00000001504746624E30
  11.    
  12.     // Property formatX in the first class has one zero more than in the second class
  13.     #define GRID_FORMAT_X2 00
  14.     #define GRID_FORMAT_X1 GRID_FORMAT_X2##0
  15.    
  16.     // These properties don't change so just copy from previous
  17.     #define GRID_FORMAT_Y1 GRID_FORMAT_X1
  18.     #define GRID_FORMAT_Y2 GRID_FORMAT_X2
  19.    
  20.     #define GRID_STEP      100
  21.    
  22.     // This is a multiplier, -1 will result in a negative number
  23.     #define GRID_STEP_Y    -1
  24.    
  25. #else
  26.    
  27.     #define GRID_ZOOMMAX2  1.00000001504747E+30
  28.    
  29.     // Property formatX in the first class has one letter more than in the second class
  30.     #define GRID_FORMAT_X2 A
  31.     #define GRID_FORMAT_X1 GRID_FORMAT_X2##a
  32.    
  33.     // Property formatY in the first class has one zero more than in the second class
  34.     #define GRID_FORMAT_Y2 0
  35.     #define GRID_FORMAT_Y1 GRID_FORMAT_Y2##0
  36.    
  37.     #define GRID_STEP      128
  38.    
  39.     // This is a multiplier, 1 means no change
  40.     #define GRID_STEP_Y    1
  41.    
  42. #endif
  43.  
  44.  
  45.  
  46.  
  47.  
  48. class Grid
  49. {
  50.     offsetX = 0;
  51.     offsetY =
  52.     #ifdef NUM_GRID 12800
  53.     #else           0
  54.     #endif          ;
  55.    
  56.    
  57.     // Zoom classes are similar so create a function-like macro
  58.     #define GRID_ZOOM(NUM, ZOOMMAX, FORMATX, FORMATY, STEP, STEP_Y, MULTIPLIER) \
  59.         class Zoom##NUM { \
  60.             zoomMax = ZOOMMAX; \
  61.             format  = "XY"; \
  62.             formatX = #FORMATX; \
  63.             formatY = #FORMATY; \
  64.             stepX   = __EVAL(STEP * MULTIPLIER); \
  65.             stepY   = __EVAL(STEP * MULTIPLIER * STEP_Y); \
  66.         };
  67.        
  68.     // NUM                - class name appendix
  69.     // #FORMATX, #FORMATY - will wrap macro in quotation marks
  70.     // __EVAL()           - calculates formula
  71.     // STEP_Y, MULTIPLIER - multipliers, in the second class the value needs to be larger
  72.    
  73.    
  74.     // Now call this function and pass to it options defined on the beginning
  75.     GRID_ZOOM(1, 0.2           ,GRID_FORMAT_X1,GRID_FORMAT_Y1, GRID_STEP, GRID_STEP_Y, 1)
  76.     GRID_ZOOM(2, GRID_ZOOMMAX2 ,GRID_FORMAT_X2,GRID_FORMAT_Y2, GRID_STEP, GRID_STEP_Y, 10)
  77.    
  78.     // This will create classes Zoom1 and Zoom2
  79.     // Be careful with whitespaces as they are not ignored in the function-like macros     
  80. };
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. /*
  90. After preprocessing with NUM_GRID macro
  91. Cleaned for readability
  92.  
  93. class Grid
  94. {
  95.     offsetX = 0;
  96.     offsetY =  12800;
  97.     class Zoom1 {
  98.         zoomMax =  0.2;
  99.         format  = "XY";
  100.         formatX = "000";
  101.         formatY = "000";
  102.         stepX   = __EVAL( 100 *  1);
  103.         stepY   = __EVAL( 100 *  1 *  -1);
  104.     };
  105.     class Zoom2 {
  106.         zoomMax = 1.00000001504746624E30;
  107.         format  = "XY";
  108.         formatX = "00";
  109.         formatY = "00";
  110.         stepX   = __EVAL( 100 *  10);
  111.         stepY   = __EVAL( 100 *  10 *  -1);
  112.     };
  113. };
  114.  
  115. After preprocessing without NUM_GRID macro
  116. Cleaned for readability
  117.  
  118. class Grid
  119. {
  120.     offsetX = 0;
  121.     offsetY = 0;
  122.     class Zoom1 {
  123.         zoomMax = 0.2;
  124.         format  = "XY";
  125.         formatX = "Aa";
  126.         formatY = "00";
  127.         stepX   = __EVAL( 128 *  1);
  128.         stepY   = __EVAL( 128 *  1 *  1);
  129.     };
  130.     class Zoom2 {
  131.         zoomMax =  1.00000001504747E+30;
  132.         format  = "XY";
  133.         formatX = "A";
  134.         formatY = "0";
  135.         stepX   = __EVAL( 128 *  10);
  136.         stepY   = __EVAL( 128 *  10 *  1);
  137.     };
  138. };
  139. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement