@@ -96,8 +96,6 @@ const BiomeInfo MapCache::biome_stub = {
9696 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }
9797};
9898
99- #define COPY (a,b ) memcpy(&a,&b,sizeof (a))
100-
10199MapExtras::Block::Block (MapCache *parent, DFCoord _bcoord) :
102100 parent(parent),
103101 designated_tiles{}
@@ -123,20 +121,19 @@ void MapExtras::Block::init()
123121
124122 if (block)
125123 {
126- COPY (designation, block->designation );
127- COPY (occupancy, block->occupancy );
128-
129- COPY (temp1, block->temperature_1 );
130- COPY (temp2, block->temperature_2 );
124+ designation = block->designation ;
125+ occupancy = block->occupancy ;
126+ temp1 = block->temperature_1 ;
127+ temp2 = block->temperature_2 ;
131128
132129 valid = true ;
133130 }
134131 else
135132 {
136- memset ( designation, 0 , sizeof (designation) );
137- memset ( occupancy, 0 , sizeof (occupancy) );
138- memset ( temp1, 0 , sizeof (temp1) );
139- memset ( temp2, 0 , sizeof (temp2) );
133+ designation. fill ({} );
134+ occupancy. fill ({} );
135+ temp1. fill ({} );
136+ temp2. fill ({} );
140137 }
141138}
142139
@@ -198,10 +195,10 @@ void MapExtras::Block::init_tiles(bool basemat)
198195MapExtras::Block::TileInfo::TileInfo ()
199196{
200197 dirty_raw.clear ();
201- memset ( raw_tiles, 0 , sizeof (raw_tiles) );
198+ raw_tiles. fill ({} );
202199 ice_info = NULL ;
203200 con_info = NULL ;
204- memset ( base_tiles, 0 , sizeof (base_tiles) );
201+ base_tiles. fill ({} );
205202}
206203
207204MapExtras::Block::TileInfo::~TileInfo ()
@@ -218,24 +215,33 @@ void MapExtras::Block::TileInfo::init_iceinfo()
218215 ice_info = new IceInfo ();
219216}
220217
218+ template <typename T>
219+ constexpr T arr40d_neg1 () {
220+ T tmp{};
221+ std::remove_reference_t <decltype (tmp[0 ])> tmp2{};
222+ tmp2.fill (-1 );
223+ tmp.fill (tmp2);
224+ return tmp;
225+ };
226+
221227void MapExtras::Block::TileInfo::init_coninfo ()
222228{
223229 if (con_info)
224230 return ;
225231
226232 con_info = new ConInfo ();
227233 con_info->constructed .clear ();
228- COPY ( con_info->tiles , base_tiles) ;
229- memset ( con_info->mat_type , - 1 , sizeof (con_info-> mat_type ) );
230- memset ( con_info->mat_index , - 1 , sizeof (con_info-> mat_index ) );
234+ con_info->tiles = base_tiles;
235+ con_info->mat_type = arr40d_neg1<t_blockmaterials>( );
236+ con_info->mat_index = arr40d_neg1<t_blockmaterials>( );
231237}
232238
233239MapExtras::Block::BasematInfo::BasematInfo ()
234240{
235241 vein_dirty.clear ();
236- memset ( mat_type, 0 , sizeof (mat_type) );
237- memset ( mat_index,- 1 , sizeof (mat_index) );
238- memset ( veinmat,- 1 , sizeof (veinmat) );
242+ mat_type. fill ({} );
243+ mat_index = arr40d_neg1<t_blockmaterials>( );
244+ veinmat = arr40d_neg1<t_blockmaterials>( );
239245}
240246
241247bool MapExtras::Block::setFlagAt (df::coord2d p, df::tile_designation::Mask mask, bool set)
@@ -481,7 +487,7 @@ void MapExtras::Block::ParseTiles(TileInfo *tiles)
481487 tiletypes40d icetiles;
482488 BlockInfo::SquashFrozenLiquids (block, icetiles);
483489
484- COPY ( tiles->raw_tiles , block->tiletype ) ;
490+ tiles->raw_tiles = block->tiletype ;
485491
486492 for (int x = 0 ; x < 16 ; x++)
487493 {
@@ -598,7 +604,7 @@ void MapExtras::Block::WriteTiles(TileInfo *tiles)
598604
599605 if (tiles->ice_info && tiles->ice_info ->dirty .has_assignments ())
600606 {
601- df::tiletype (* newtiles)[ 16 ] = (tiles->con_info ? tiles->con_info ->tiles : tiles->base_tiles );
607+ auto newtiles = (tiles->con_info ? tiles->con_info ->tiles : tiles->base_tiles );
602608
603609 for (int i = block->block_events .size ()-1 ; i >= 0 ; i--)
604610 {
@@ -646,8 +652,8 @@ void MapExtras::Block::ParseBasemats(TileInfo *tiles, BasematInfo *bmats)
646652
647653 info.prepare (this );
648654
649- COPY ( bmats->veinmat , info.veinmats ) ;
650- COPY ( bmats->veintype , info.veintype ) ;
655+ bmats->veinmat = info.veinmats ;
656+ bmats->veintype = info.veintype ;
651657
652658 for (int x = 0 ; x < 16 ; x++)
653659 {
@@ -779,7 +785,7 @@ bool MapExtras::Block::Write ()
779785
780786 if (dirty_designations)
781787 {
782- COPY ( block->designation , designation) ;
788+ block->designation = designation;
783789 block->flags .bits .designated = true ;
784790 block->dsgn_check_cooldown = 0 ;
785791 dirty_designations = false ;
@@ -798,13 +804,13 @@ bool MapExtras::Block::Write ()
798804 }
799805 if (dirty_temperatures)
800806 {
801- COPY ( block->temperature_1 , temp1) ;
802- COPY ( block->temperature_2 , temp2) ;
807+ block->temperature_1 = temp1;
808+ block->temperature_2 = temp2;
803809 dirty_temperatures = false ;
804810 }
805811 if (dirty_occupancies)
806812 {
807- COPY ( block->occupancy , occupancy) ;
813+ block->occupancy = occupancy;
808814 dirty_occupancies = false ;
809815 }
810816 return true ;
@@ -1034,8 +1040,8 @@ void MapExtras::BlockInfo::SquashVeins(df::map_block *mb, t_blockmaterials & mat
10341040{
10351041 std::vector <df::block_square_event_mineralst *> veins;
10361042 Maps::SortBlockEvents (mb,&veins);
1037- memset ( materials,- 1 , sizeof (materials) );
1038- memset ( veintype, 0 , sizeof (t_veintype) );
1043+ materials = arr40d_neg1<t_blockmaterials>( );
1044+ veintype. fill ({} );
10391045
10401046 for (uint32_t x = 0 ;x<16 ;x++) for (uint32_t y = 0 ; y< 16 ;y++)
10411047 {
@@ -1054,7 +1060,7 @@ void MapExtras::BlockInfo::SquashFrozenLiquids(df::map_block *mb, tiletypes40d &
10541060{
10551061 std::vector <df::block_square_event_frozen_liquidst *> ices;
10561062 Maps::SortBlockEvents (mb,NULL ,&ices);
1057- memset ( frozen, 0 , sizeof (frozen) );
1063+ frozen. fill ({} );
10581064 for (uint32_t x = 0 ; x < 16 ; x++) for (uint32_t y = 0 ; y < 16 ; y++)
10591065 {
10601066 for (size_t i = 0 ; i < ices.size (); i++)
@@ -1089,7 +1095,7 @@ void MapExtras::BlockInfo::SquashGrass(df::map_block *mb, t_blockmaterials &mate
10891095{
10901096 std::vector<df::block_square_event_grassst*> grasses;
10911097 Maps::SortBlockEvents (mb, NULL , NULL , NULL , &grasses);
1092- memset ( materials,- 1 , sizeof (materials) );
1098+ materials = arr40d_neg1<t_blockmaterials>( );
10931099 for (uint32_t x = 0 ; x < 16 ; x++) for (uint32_t y = 0 ; y < 16 ; y++)
10941100 {
10951101 int amount = 0 ;
0 commit comments