Loading

Paste #ptg3woh3x

  1. diff --git a/src/cargo_type.h b/src/cargo_type.h
  2. index 402e81c1b..c84f1f490 100644
  3. --- a/src/cargo_type.h
  4. +++ b/src/cargo_type.h
  5. @@ -63,14 +63,14 @@ enum CargoType {
  6.     CT_PLASTIC      = 10,
  7.     CT_FIZZY_DRINKS = 11,
  8.  
  9. -   NUM_CARGO       = 32,   ///< Maximal number of cargo types in a game.
  10. +   NUM_CARGO       = 64,   ///< Maximal number of cargo types in a game.
  11.  
  12.     CT_AUTO_REFIT   = 0xFD, ///< Automatically choose cargo type when doing auto refitting.
  13.     CT_NO_REFIT     = 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
  14.     CT_INVALID      = 0xFF, ///< Invalid cargo type.
  15.  };
  16.  
  17. -typedef uint32 CargoTypes;
  18. +typedef uint64 CargoTypes;
  19.  
  20.  static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT32_MAX;
  21.  
  22. diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp
  23. index 31e679b00..72026fa6a 100644
  24. --- a/src/core/bitmath_func.hpp
  25. +++ b/src/core/bitmath_func.hpp
  26. @@ -12,6 +12,8 @@
  27.  #ifndef BITMATH_FUNC_HPP
  28.  #define BITMATH_FUNC_HPP
  29.  
  30. +#include <bitset>
  31. +
  32.  /**
  33.   * Fetch \a n bits from \a x, started at bit \a s.
  34.   *
  35. @@ -108,6 +110,22 @@ static inline bool HasBit(const T x, const uint8 y)
  36.  }
  37.  
  38.  /**
  39. + * Checks if a bit in a std::bitset is set.
  40. + *
  41. + * This function is a wrapper for std::bitset.test().
  42. + *
  43. + * @param x The value to check
  44. + * @param y The position of the bit to check, started from the LSB
  45. + * @pre y < N
  46. + * @return True if the bit is set, false else.
  47. + */
  48. +template <size_t N>
  49. +static inline bool HasBit(const std::bitset<N> x, const uint8 y)
  50. +{
  51. +   return x.test(y);
  52. +}
  53. +
  54. +/**
  55.   * Set a bit in a variable.
  56.   *
  57.   * This function sets a bit in a variable. The variable is changed
  58. @@ -126,6 +144,22 @@ static inline T SetBit(T &x, const uint8 y)
  59.  }
  60.  
  61.  /**
  62. + * Set a bit in a std::bitset.
  63. + *
  64. + * This function is a wrapper for std::bitset.set().
  65. + *
  66. + * @param x The variable to set a bit
  67. + * @param y The bit position to set
  68. + * @pre y < N
  69. + * @return The new value of the old value with the bit set
  70. + */
  71. +template <size_t N>
  72. +static inline std::bitset<N> SetBit(const std::bitset<N> &x, const uint8 y)
  73. +{
  74. +   return x.set(y);
  75. +}
  76. +
  77. +/**
  78.   * Sets several bits in a variable.
  79.   *
  80.   * This macro sets several bits in a variable. The bits to set are provided
  81. @@ -156,6 +190,22 @@ static inline T ClrBit(T &x, const uint8 y)
  82.  }
  83.  
  84.  /**
  85. + * Clears a bit in a std::bitset.
  86. + *
  87. + * This function is a wrapper for std::bitset.clear().
  88. + *
  89. + * @param x The variable to clear the bit
  90. + * @param y The bit position to clear
  91. + * @pre y < N
  92. + * @return The new value of the old value with the bit cleared
  93. + */
  94. +template <size_t N>
  95. +static inline std::bitset<N> ClrBit(const std::bitset<N> &x, const uint8 y)
  96. +{
  97. +   return x.reset(y);
  98. +}
  99. +
  100. +/**
  101.   * Clears several bits in a variable.
  102.   *
  103.   * This macro clears several bits in a variable. The bits to clear are
  104. @@ -185,6 +235,21 @@ static inline T ToggleBit(T &x, const uint8 y)
  105.     return x = (T)(x ^ ((T)1U << y));
  106.  }
  107.  
  108. +/**
  109. + * Toggles a bit in a std::bitset.
  110. + *
  111. + * This function is a wrapper for std::bitset.flip().
  112. + *
  113. + * @param x The variable to toggle the bit
  114. + * @param y The bit position to toggle
  115. + * @pre y < N
  116. + * @return The new value of the old value with the bit toggled
  117. + */
  118. +template <size_t N>
  119. +static inline std::bitset<N> ToggleBit(const std::bitset<N> &x, const uint8 y)
  120. +{
  121. +   return x.flip(y);
  122. +}
  123.  
  124.  /** Lookup table to check which bit is set in a 6 bit variable */
  125.  extern const uint8 _ffb_64[64];
  126. @@ -267,6 +332,20 @@ static inline uint CountBits(T value)
  127.  }
  128.  
  129.  /**
  130. + * Counts the number of set bits in a std::bitset.
  131. + *
  132. + * This function is a wrapper for std::bitset.count().
  133. + *
  134. + * @param value the value to count the number of bits in.
  135. + * @return the number of bits.
  136. + */
  137. +template <size_t N>
  138. +static inline uint CountBits(const std::bitset<N> value)
  139. +{
  140. +   return (uint)value.count();
  141. +}
  142. +
  143. +/**
  144.   * Test whether \a value has exactly 1 bit set
  145.   *
  146.   * @param value the value to test.
  147. @@ -279,6 +358,18 @@ static inline bool HasExactlyOneBit(T value)
  148.  }
  149.  
  150.  /**
  151. + * Test whether \a std::bitset has exactly 1 bit set.
  152. + *
  153. + * @param value the value to test.
  154. + * @return does \a value have exactly 1 bit set?
  155. + */
  156. +template <size_t N>
  157. +static inline bool HasExactlyOneBit(const std::bitset<N> value)
  158. +{
  159. +   return value.count() == 1;
  160. +}
  161. +
  162. +/**
  163.   * Test whether \a value has at most 1 bit set
  164.   *
  165.   * @param value the value to test.
  166. diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
  167. index c12c6ace4..b119fbffd 100644
  168. --- a/src/graph_gui.cpp
  169. +++ b/src/graph_gui.cpp
  170. @@ -33,8 +33,8 @@
  171.  #include "safeguards.h"
  172.  
  173.  /* Bitmasks of company and cargo indices that shouldn't be drawn. */
  174. -static uint _legend_excluded_companies;
  175. -static uint _legend_excluded_cargo;
  176. +static CompanyMask _legend_excluded_companies;
  177. +static CargoTypes _legend_excluded_cargo;
  178.  
  179.  /* Apparently these don't play well with enums. */
  180.  static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn.
  181. @@ -166,14 +166,14 @@ struct ValuesInterval {
  182.  
  183.  struct BaseGraphWindow : Window {
  184.  protected:
  185. -   static const int GRAPH_MAX_DATASETS     =  32;
  186. +   static const int GRAPH_MAX_DATASETS     =  64;
  187.     static const int GRAPH_AXIS_LINE_COLOUR = PC_BLACK;
  188.     static const int GRAPH_NUM_MONTHS       =  24; ///< Number of months displayed in the graph.
  189.  
  190.     static const int MIN_GRAPH_NUM_LINES_Y  =   9; ///< Minimal number of horizontal lines to draw.
  191.     static const int MIN_GRID_PIXEL_SIZE    =  20; ///< Minimum distance between graph lines.
  192.  
  193. -   uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
  194. +   std::bitset<GRAPH_MAX_DATASETS> excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
  195.     byte num_dataset;
  196.     byte num_on_x_axis;
  197.     byte num_vert_lines;
  198. @@ -561,7 +561,7 @@ public:
  199.      */
  200.     void UpdateStatistics(bool initialize)
  201.     {
  202. -       uint excluded_companies = _legend_excluded_companies;
  203. +       CompanyMask excluded_companies = _legend_excluded_companies;
  204.  
  205.         /* Exclude the companies which aren't valid */
  206.         for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
  207. @@ -902,7 +902,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
  208.  
  209.     void UpdateExcludedData()
  210.     {
  211. -       this->excluded_data = 0;
  212. +       this->excluded_data.reset();
  213.  
  214.         int i = 0;
  215.         const CargoSpec *cs;
  216. @@ -967,7 +967,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
  217.             case WID_CPR_ENABLE_CARGOES:
  218.                 /* Remove all cargoes from the excluded lists. */
  219.                 _legend_excluded_cargo = 0;
  220. -               this->excluded_data = 0;
  221. +               this->excluded_data.reset();
  222.                 this->UpdateLoweredWidgets();
  223.                 this->SetDirty();
  224.                 break;
  225. diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp
  226. index 9a9056061..07d685e92 100644
  227. --- a/src/saveload/company_sl.cpp
  228. +++ b/src/saveload/company_sl.cpp
  229. @@ -350,7 +350,8 @@ static const SaveLoad _company_economy_desc[] = {
  230.     SLE_CONDVAR(CompanyEconomyEntry, company_value,       SLE_INT64,                  2, SL_MAX_VERSION),
  231.  
  232.     SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32,       0, 169),
  233. -   SLE_CONDARR(CompanyEconomyEntry, delivered_cargo,     SLE_UINT32, NUM_CARGO,    170, SL_MAX_VERSION),
  234. +   SLE_CONDARR(CompanyEconomyEntry, delivered_cargo,     SLE_UINT32, 32,           170, 198),
  235. +   SLE_CONDARR(CompanyEconomyEntry, delivered_cargo,     SLE_UINT32, NUM_CARGO,    199, SL_MAX_VERSION),
  236.         SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
  237.  
  238.     SLE_END()
  239. diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp
  240. index dabf120fc..0effb5b2f 100644
  241. --- a/src/saveload/economy_sl.cpp
  242. +++ b/src/saveload/economy_sl.cpp
  243. @@ -29,7 +29,7 @@ static void Load_PRIC()
  244.  /** Cargo payment rates in pre 126 savegames */
  245.  static void Load_CAPR()
  246.  {
  247. -   uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO;
  248. +   uint num_cargo = IsSavegameVersionBefore(55) ? 12 : IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
  249.     int vt = IsSavegameVersionBefore(65) ? SLE_FILE_I32 : SLE_FILE_I64;
  250.     SlArray(NULL, num_cargo, vt | SLE_VAR_NULL);
  251.     SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
  252. diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
  253. index d06214e23..692f73cf2 100644
  254. --- a/src/saveload/saveload.cpp
  255. +++ b/src/saveload/saveload.cpp
  256. @@ -266,8 +266,9 @@
  257.   *  196   27778   1.7.x
  258.   *  197   27978   1.8.x
  259.   *  198
  260. + *  199
  261.   */
  262. -extern const uint16 SAVEGAME_VERSION = 198; ///< Current savegame version of OpenTTD.
  263. +extern const uint16 SAVEGAME_VERSION = 199; ///< Current savegame version of OpenTTD.
  264.  
  265.  SavegameType _savegame_type; ///< type of savegame we are loading
  266.  FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
  267. diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp
  268. index 391ba30a8..f01123da0 100644
  269. --- a/src/saveload/station_sl.cpp
  270. +++ b/src/saveload/station_sl.cpp
  271. @@ -329,6 +329,7 @@ static void Load_STNS()
  272.     _cargo_days = 0;
  273.     _cargo_feeder_share = 0;
  274.  
  275. +   uint num_cargo = IsSavegameVersionBefore(55) ? 12 : IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
  276.     int index;
  277.     while ((index = SlIterateArray()) != -1) {
  278.         Station *st = new (index) Station();
  279. @@ -337,7 +338,6 @@ static void Load_STNS()
  280.  
  281.         _waiting_acceptance = 0;
  282.  
  283. -       uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO;
  284.         for (CargoID i = 0; i < num_cargo; i++) {
  285.             GoodsEntry *ge = &st->goods[i];
  286.             SlObject(ge, GetGoodsDesc());
  287. @@ -377,10 +377,11 @@ static void Ptrs_STNS()
  288.     /* Don't run when savegame version is higher than or equal to 123. */
  289.     if (!IsSavegameVersionBefore(123)) return;
  290.  
  291. +   uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
  292.     Station *st;
  293.     FOR_ALL_STATIONS(st) {
  294.         if (!IsSavegameVersionBefore(68)) {
  295. -           for (CargoID i = 0; i < NUM_CARGO; i++) {
  296. +           for (CargoID i = 0; i < num_cargo; i++) {
  297.                 GoodsEntry *ge = &st->goods[i];
  298.                 SwapPackets(ge);
  299.                 SlObject(ge, GetGoodsDesc());
  300. @@ -440,7 +441,8 @@ static const SaveLoad _station_desc[] = {
  301.           SLE_VAR(Station, last_vehicle_type,          SLE_UINT8),
  302.           SLE_VAR(Station, had_vehicle_of_type,        SLE_UINT8),
  303.           SLE_LST(Station, loading_vehicles,           REF_VEHICLE),
  304. -     SLE_CONDVAR(Station, always_accepted,            SLE_UINT32, 127, SL_MAX_VERSION),
  305. +     SLE_CONDVAR(Station, always_accepted,            SLE_FILE_U32 | SLE_VAR_U64, 127, 198),
  306. +     SLE_CONDVAR(Station, always_accepted,            SLE_UINT64,                 199, SL_MAX_VERSION),
  307.  
  308.           SLE_END()
  309.  };
  310. @@ -520,6 +522,7 @@ static void Load_STNN()
  311.  {
  312.     _num_flows = 0;
  313.  
  314. +   uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
  315.     int index;
  316.     while ((index = SlIterateArray()) != -1) {
  317.         bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0;
  318. @@ -538,7 +541,7 @@ static void Load_STNN()
  319.                 memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(st->airport.psa->storage));
  320.             }
  321.  
  322. -           for (CargoID i = 0; i < NUM_CARGO; i++) {
  323. +           for (CargoID i = 0; i < num_cargo; i++) {
  324.                 SlObject(&st->goods[i], GetGoodsDesc());
  325.                 FlowSaveLoad flow;
  326.                 FlowStat *fs = NULL;
  327. @@ -580,9 +583,10 @@ static void Ptrs_STNN()
  328.     /* Don't run when savegame version lower than 123. */
  329.     if (IsSavegameVersionBefore(123)) return;
  330.  
  331. +   uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
  332.     Station *st;
  333.     FOR_ALL_STATIONS(st) {
  334. -       for (CargoID i = 0; i < NUM_CARGO; i++) {
  335. +       for (CargoID i = 0; i < num_cargo; i++) {
  336.             GoodsEntry *ge = &st->goods[i];
  337.             if (IsSavegameVersionBefore(183)) {
  338.                 SwapPackets(ge);
  339. diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
  340. index 41ac70165..13438d85b 100644
  341. --- a/src/saveload/town_sl.cpp
  342. +++ b/src/saveload/town_sl.cpp
  343. @@ -192,7 +192,8 @@ static const SaveLoad _town_desc[] = {
  344.  
  345.     SLE_CONDLST(Town, psa_list,            REF_STORAGE,                161, SL_MAX_VERSION),
  346.  
  347. -   SLE_CONDVAR(Town, cargo_produced,       SLE_UINT32,                166, SL_MAX_VERSION),
  348. +   SLE_CONDVAR(Town, cargo_produced,        SLE_FILE_U32 | SLE_VAR_U64, 166, 198),
  349. +   SLE_CONDVAR(Town, cargo_produced,        SLE_UINT64,                 199, SL_MAX_VERSION),
  350.  
  351.     /* reserve extra space in savegame here. (currently 30 bytes) */
  352.     SLE_CONDNULL(30, 2, SL_MAX_VERSION),
  353. @@ -274,12 +275,13 @@ static void Save_TOWN()
  354.  static void Load_TOWN()
  355.  {
  356.     int index;
  357. +   uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
  358.  
  359.     while ((index = SlIterateArray()) != -1) {
  360.         Town *t = new (index) Town();
  361.         SlObject(t, _town_desc);
  362.  
  363. -       for (CargoID i = 0; i < NUM_CARGO; i++) {
  364. +       for (CargoID i = 0; i < num_cargo; i++) {
  365.             SlObject(&t->supplied[i], _town_supplied_desc);
  366.         }
  367.         for (int i = TE_BEGIN; i < TE_END; i++) {
  368. diff --git a/src/strings.cpp b/src/strings.cpp
  369. index fd45e6a0b..63d8e69d4 100644
  370. --- a/src/strings.cpp
  371. +++ b/src/strings.cpp
  372. @@ -1147,7 +1147,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
  373.             }
  374.  
  375.             case SCC_CARGO_LIST: { // {CARGO_LIST}
  376. -               CargoTypes cmask = args->GetInt32(SCC_CARGO_LIST);
  377. +               CargoTypes cmask = args->GetInt64(SCC_CARGO_LIST);
  378.                 bool first = true;
  379.  
  380.                 const CargoSpec *cs;
  381. diff --git a/src/window.cpp b/src/window.cpp
  382. index e2ce84542..f17fccf93 100644
  383. --- a/src/window.cpp
  384. +++ b/src/window.cpp
  385. @@ -2457,20 +2457,20 @@ static EventState HandleViewportScroll()
  386.     }
  387.  
  388.     Point delta;
  389. +   if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
  390. +       delta.x = -_cursor.delta.x;
  391. +       delta.y = -_cursor.delta.y;
  392. +   } else {
  393. +       delta.x = _cursor.delta.x;
  394. +       delta.y = _cursor.delta.y;
  395. +   }
  396. +
  397.     if (scrollwheel_scrolling) {
  398.         /* We are using scrollwheels for scrolling */
  399.         delta.x = _cursor.h_wheel;
  400.         delta.y = _cursor.v_wheel;
  401.         _cursor.v_wheel = 0;
  402.         _cursor.h_wheel = 0;
  403. -   } else {
  404. -       if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
  405. -           delta.x = -_cursor.delta.x;
  406. -           delta.y = -_cursor.delta.y;
  407. -       } else {
  408. -           delta.x = _cursor.delta.x;
  409. -           delta.y = _cursor.delta.y;
  410. -       }
  411.     }
  412.  
  413.     /* Create a scroll-event and send it to the window */
  414. @@ -2866,12 +2866,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
  415.     }
  416.  
  417.     if (vp != NULL) {
  418. -       if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
  419. -           _scrolling_viewport = true;
  420. -           _cursor.fix_at = true;
  421. -           return;
  422. -       }
  423. -
  424. +       if (scrollwheel_scrolling) click = MC_RIGHT; // we are using the scrollwheel in a viewport, so we emulate right mouse button
  425.         switch (click) {
  426.             case MC_DOUBLE_LEFT:
  427.             case MC_LEFT:
  428. @@ -2890,6 +2885,10 @@ static void MouseLoop(MouseClick click, int mousewheel)
  429.                     _scrolling_viewport = true;
  430.                     _cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
  431.                             _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
  432. +
  433. +                   /* clear 2D scrolling caches before we start a 2D scroll */
  434. +                   _cursor.h_wheel = 0;
  435. +                   _cursor.v_wheel = 0;
  436.                     return;
  437.                 }
  438.                 break;
  439. @@ -2904,7 +2903,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
  440.             case MC_LEFT:
  441.             case MC_DOUBLE_LEFT:
  442.                 DispatchLeftClickEvent(w, x - w->left, y - w->top, click == MC_DOUBLE_LEFT ? 2 : 1);
  443. -               return;
  444. +               break;
  445.  
  446.             default:
  447.                 if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break;
  448. @@ -2912,19 +2911,11 @@ static void MouseLoop(MouseClick click, int mousewheel)
  449.                  * Simulate a right button click so we can get started. */
  450.                 FALLTHROUGH;
  451.  
  452. -           case MC_RIGHT:
  453. -               DispatchRightClickEvent(w, x - w->left, y - w->top);
  454. -               return;
  455. +           case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
  456.  
  457. -           case MC_HOVER:
  458. -               DispatchHoverEvent(w, x - w->left, y - w->top);
  459. -               break;
  460. +           case MC_HOVER: DispatchHoverEvent(w, x - w->left, y - w->top); break;
  461.         }
  462.     }
  463. -
  464. -   /* We're not doing anything with 2D scrolling, so reset the value.  */
  465. -   _cursor.h_wheel = 0;
  466. -   _cursor.v_wheel = 0;
  467.  }
  468.  
  469.  /**

Comments