Loading

Paste #pd1dwssuu

  1. diff --git a/src/map.cpp b/src/map.cpp
  2. index 81985be..d79f910 100644
  3. --- a/src/map.cpp
  4. +++ b/src/map.cpp
  5. @@ -495,27 +495,51 @@ TileOwner VoxelWorld::GetTileOwner(uint16 x, uint16 y)
  6.         return this->GetStack(x, y)->owner;
  7.  }
  8.  
  9. -/** Map of imploded base ground slope to mask of fence nibbles at the base voxel. */
  10. +/**
  11. + * At ground level of each voxel stack are 4 fences, one at each edge (ordered as #EDGE_NE .. # EDGE_NW).
  12. + * Due to slopes, some fences are at the bottom voxel (the base voxel) of the ground level, the other
  13. + * fences are at the top voxel. The rule for placement is
  14. + * - Both fences near the top edge of a steep slope are in the top voxel.
  15. + * - Both fences near the bottom edge of a steep slope are in the bottom voxel.
  16. + * - Fences on edges of non-steep slopes with both corners raised are in the top voxel.
  17. + * - Other fences of non-steep slopes are in the bottom voxel.
  18. + *
  19. + * Each voxel has the possibility to store 4 fences (one at each edge). In the general case with a
  20. + * base voxel and a top voxel, there are 8 positions for fences, where 4 of them are used to store
  21. + * ground level fences. Below is the mask for getting the fences at base voxel level, for each non-top slope.
  22. + * A \c 0xF nibble means the fence is stored in the base voxel, a \c 0x0 nibble means the fence is stored
  23. + * in the top voxel. (Top-slopes make no sense to include here, as they only describe the top voxel.)
  24. + *
  25. + * To work with the masks, the following functions exist:
  26. + * - #MergeGroundFencesAtBase sets the given fences for the base voxel.
  27. + * - #HasTopVoxelFences tells whether the slope has any fences in the top voxel (that is, does it have a top voxel at all?)
  28. + * - #MergeGroundFencesAtTop sets the given fences for the top voxel.
  29. + *
  30. + * The following functions interact with the map.
  31. + * - #GetGroundFencesFromMap gets the fences at ground level from a voxel stack.
  32. + * - #AddGroundFencesToMap sets the fences to a voxel stack.
  33. + *
  34. + */
  35.  static const uint16 _fences_mask_at_base[] = {
  36. -       0xFFFF, //  0
  37. -       0xFFFF, //  1
  38. -       0xFFFF, //  2
  39. -       0xFFF0, //  3
  40. -       0xFFFF, //  4
  41. -       0xFFFF, //  5
  42. -       0xFF0F, //  6
  43. -       0xFF00, //  7
  44. -       0xFFFF, //  8
  45. -       0x0FFF, //  9
  46. -       0xFFFF, // 10
  47. -       0x0FF0, // 11
  48. -       0xF0FF, // 12
  49. -       0x00FF, // 13
  50. -       0xF00F, // 14
  51. -       0x0FF0, // 15 base steep north
  52. -       0xFF00, // 16 base steep east
  53. -       0xF00F, // 17 base steep south
  54. -       0x00FF, // 18 base steep west
  55. +       0xFFFF, // Imploded ground slope  0
  56. +       0xFFFF, // Imploded ground slope  1
  57. +       0xFFFF, // Imploded ground slope  2
  58. +       0xFFF0, // Imploded ground slope  3
  59. +       0xFFFF, // Imploded ground slope  4
  60. +       0xFFFF, // Imploded ground slope  5
  61. +       0xFF0F, // Imploded ground slope  6
  62. +       0xFF00, // Imploded ground slope  7
  63. +       0xFFFF, // Imploded ground slope  8
  64. +       0x0FFF, // Imploded ground slope  9
  65. +       0xFFFF, // Imploded ground slope 10
  66. +       0x0FF0, // Imploded ground slope 11
  67. +       0xF0FF, // Imploded ground slope 12
  68. +       0x00FF, // Imploded ground slope 13
  69. +       0xF00F, // Imploded ground slope 14
  70. +       0x0FF0, // Imploded ground slope 15 (base steep north)
  71. +       0xFF00, // Imploded ground slope 16 (base steep east)
  72. +       0xF00F, // Imploded ground slope 17 (base steep south)
  73. +       0x00FF, // Imploded ground slope 18 (base steep west)
  74.  };
  75.  
  76.  /**
  77. @@ -529,8 +553,8 @@ uint16 MergeGroundFencesAtBase(uint16 vxbase_fences, uint16 fences, uint8 base_t
  78.  {
  79.         assert(base_tile_slope < lengthof(_fences_mask_at_base)); // Top steep slopes are not allowed.
  80.         uint16 mask = _fences_mask_at_base[base_tile_slope];
  81. -       fences &= mask;
  82. -       mask ^= 0xFFFF;
  83. +       fences &= mask; // Kill any fence not in the base voxel.
  84. +       mask ^= 0xFFFF; // Swap mask to keep only non-fences of the current voxel data.
  85.         return (vxbase_fences & mask) | fences;
  86.  }
  87.  
  88. @@ -556,8 +580,8 @@ uint16 MergeGroundFencesAtTop(uint16 vxtop_fences, uint16 fences, uint8 base_til
  89.  {
  90.         assert(base_tile_slope < lengthof(_fences_mask_at_base)); // Top steep slopes are not allowed.
  91.         uint16 mask = _fences_mask_at_base[base_tile_slope];
  92. -       vxtop_fences &= mask;
  93. -       mask ^= 0xFFFF;
  94. +       vxtop_fences &= mask; // Keep fences of top voxel that are at ground level in the base voxel.
  95. +       mask ^= 0xFFFF; // Swap mask to keep fences that belong in the top voxel.
  96.         return (fences & mask) | vxtop_fences;
  97.  }
  98.  
  99. @@ -592,12 +616,12 @@ uint16 GetGroundFencesFromMap(const VoxelStack *stack, int base_z)
  100.  
  101.         assert(slope < lengthof(_fences_mask_at_base)); // Top steep slopes are not allowed.
  102.         uint16 mask = _fences_mask_at_base[slope];
  103. -       uint16 fences = v->GetFences() & mask;
  104. +       uint16 fences = v->GetFences() & mask; // Get ground level fences of the base voxel.
  105.         if (HasTopVoxelFences(slope)) {
  106.                 v = stack->Get(base_z + 1);
  107.                 uint top_fences = (v != nullptr) ? v->GetFences() : ALL_INVALID_FENCES;
  108. -               mask ^= 0xFFFF;
  109. -               fences |= top_fences & mask;
  110. +               mask ^= 0xFFFF; // Swap all bits to top voxel mask.
  111. +               fences |= top_fences & mask; // Add fences of the top voxel.
  112.         }
  113.         return fences;
  114.  }

Comments