Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/DataStatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace {
DFHack::VersionInfo *global_table_ = DFHack::Core::getInstance().vinfo.get(); \
void * tmp_;

#define INIT_GLOBAL_FUNCTION_ITEM(type,name) \
if (global_table_->getAddress(#name,tmp_)) name = (type*)tmp_;
#define INIT_GLOBAL_FUNCTION_ITEM(name, ...) \
if (global_table_->getAddress(#name,tmp_)) name = (__VA_ARGS__*)tmp_;

#define TID(type) (&identity_traits< type >::identity)

Expand Down
12 changes: 12 additions & 0 deletions library/include/DataIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ namespace df
static const container_identity *get();
};

template<class T, size_t sz> struct identity_traits<std::array<T, sz>>
{
static const container_identity* get();
};

template<class T> struct identity_traits<std::vector<T> > {
static const container_identity *get();
};
Expand Down Expand Up @@ -797,6 +802,13 @@ namespace df
return &identity;
}

template<class T, size_t sz>
inline const container_identity* identity_traits<std::array<T,sz>>::get()
{
static const buffer_container_identity identity(sz, identity_traits<T>::get());
return &identity;
}

template<class T>
inline const container_identity *identity_traits<std::vector<T> >::get() {
using container = std::vector<T>;
Expand Down
4 changes: 2 additions & 2 deletions library/include/df/custom/tile_bitmask.methods.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ inline uint16_t &operator[] (int y)
}
void clear()
{
memset(bits,0,sizeof(bits));
bits.fill(0);
}
void set_all()
{
memset(bits,0xFF,sizeof(bits));
bits.fill(-1);
}
inline bool getassignment( const df::coord2d &xy )
{
Expand Down
4 changes: 2 additions & 2 deletions library/include/modules/MapCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct BiomeInfo {
int16_t layer_stone[MAX_LAYERS];
};

typedef uint8_t t_veintype[16][16];
typedef df::tiletype t_tilearr[16][16];
using t_veintype = arr40d<uint8_t>;
using t_tilearr = arr40d<df::tiletype>;

class BlockInfo
{
Expand Down
14 changes: 9 additions & 5 deletions library/include/modules/Maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,32 @@ enum BiomeOffset {
*/
typedef df::block_flags t_blockflags;

template <typename T>
using arr40d = std::array<std::array<T, 16>, 16>;

/**
* 16x16 array of tile types
* \ingroup grp_maps
*/
typedef df::tiletype tiletypes40d [16][16];
using tiletypes40d = arr40d<df::tiletype>;
/**
* 16x16 array used for squashed block materials
* \ingroup grp_maps
*/
typedef int16_t t_blockmaterials [16][16];
using t_blockmaterials = arr40d<int16_t>;
/**
* 16x16 array of designation flags
* \ingroup grp_maps
*/
typedef df::tile_designation t_designation;
typedef t_designation designations40d [16][16];
using designations40d = arr40d<t_designation>;

/**
* 16x16 array of occupancy flags
* \ingroup grp_maps
*/
typedef df::tile_occupancy t_occupancy;
typedef t_occupancy occupancies40d [16][16];
using occupancies40d = arr40d<t_occupancy>;
/**
* array of 16 biome indexes valid for the block
* \ingroup grp_maps
Expand All @@ -157,7 +161,7 @@ typedef uint8_t biome_indices40d [9];
* 16x16 array of temperatures
* \ingroup grp_maps
*/
typedef uint16_t t_temperatures [16][16];
using t_temperatures = arr40d<uint16_t>;

/**
* Index a tile array by a 2D coordinate, clipping it to mod 16.
Expand Down
68 changes: 37 additions & 31 deletions library/modules/MapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const BiomeInfo MapCache::biome_stub = {
-1, -1, -1, -1, -1, -1, -1, -1 }
};

#define COPY(a,b) memcpy(&a,&b,sizeof(a))

MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) :
parent(parent),
designated_tiles{}
Expand All @@ -123,20 +121,19 @@ void MapExtras::Block::init()

if(block)
{
COPY(designation, block->designation);
COPY(occupancy, block->occupancy);

COPY(temp1, block->temperature_1);
COPY(temp2, block->temperature_2);
designation = block->designation;
occupancy = block->occupancy;
temp1 = block->temperature_1;
temp2 = block->temperature_2;

valid = true;
}
else
{
memset(designation,0,sizeof(designation));
memset(occupancy,0,sizeof(occupancy));
memset(temp1,0,sizeof(temp1));
memset(temp2,0,sizeof(temp2));
designation.fill({});
occupancy.fill({});
temp1.fill({});
temp2.fill({});
}
}

Expand Down Expand Up @@ -198,10 +195,10 @@ void MapExtras::Block::init_tiles(bool basemat)
MapExtras::Block::TileInfo::TileInfo()
{
dirty_raw.clear();
memset(raw_tiles,0,sizeof(raw_tiles));
raw_tiles.fill({});
ice_info = NULL;
con_info = NULL;
memset(base_tiles,0,sizeof(base_tiles));
base_tiles.fill({});
}

MapExtras::Block::TileInfo::~TileInfo()
Expand All @@ -218,24 +215,33 @@ void MapExtras::Block::TileInfo::init_iceinfo()
ice_info = new IceInfo();
}

template <typename T>
constexpr T arr40d_neg1() {
T tmp{};
std::remove_reference_t<decltype(tmp[0])> tmp2{};
tmp2.fill(-1);
tmp.fill(tmp2);
return tmp;
};

void MapExtras::Block::TileInfo::init_coninfo()
{
if (con_info)
return;

con_info = new ConInfo();
con_info->constructed.clear();
COPY(con_info->tiles, base_tiles);
memset(con_info->mat_type, -1, sizeof(con_info->mat_type));
memset(con_info->mat_index, -1, sizeof(con_info->mat_index));
con_info->tiles = base_tiles;
con_info->mat_type = arr40d_neg1<t_blockmaterials>();
con_info->mat_index = arr40d_neg1<t_blockmaterials>();
}

MapExtras::Block::BasematInfo::BasematInfo()
{
vein_dirty.clear();
memset(mat_type,0,sizeof(mat_type));
memset(mat_index,-1,sizeof(mat_index));
memset(veinmat,-1,sizeof(veinmat));
mat_type.fill({});
mat_index = arr40d_neg1<t_blockmaterials>();
veinmat = arr40d_neg1<t_blockmaterials>();
}

bool MapExtras::Block::setFlagAt(df::coord2d p, df::tile_designation::Mask mask, bool set)
Expand Down Expand Up @@ -481,7 +487,7 @@ void MapExtras::Block::ParseTiles(TileInfo *tiles)
tiletypes40d icetiles;
BlockInfo::SquashFrozenLiquids(block, icetiles);

COPY(tiles->raw_tiles, block->tiletype);
tiles->raw_tiles = block->tiletype;

for (int x = 0; x < 16; x++)
{
Expand Down Expand Up @@ -598,7 +604,7 @@ void MapExtras::Block::WriteTiles(TileInfo *tiles)

if (tiles->ice_info && tiles->ice_info->dirty.has_assignments())
{
df::tiletype (*newtiles)[16] = (tiles->con_info ? tiles->con_info->tiles : tiles->base_tiles);
auto newtiles = (tiles->con_info ? tiles->con_info->tiles : tiles->base_tiles);

for (int i = block->block_events.size()-1; i >= 0; i--)
{
Expand Down Expand Up @@ -646,8 +652,8 @@ void MapExtras::Block::ParseBasemats(TileInfo *tiles, BasematInfo *bmats)

info.prepare(this);

COPY(bmats->veinmat, info.veinmats);
COPY(bmats->veintype, info.veintype);
bmats->veinmat = info.veinmats;
bmats->veintype = info.veintype;

for (int x = 0; x < 16; x++)
{
Expand Down Expand Up @@ -779,7 +785,7 @@ bool MapExtras::Block::Write ()

if(dirty_designations)
{
COPY(block->designation, designation);
block->designation = designation;
block->flags.bits.designated = true;
block->dsgn_check_cooldown = 0;
dirty_designations = false;
Expand All @@ -798,13 +804,13 @@ bool MapExtras::Block::Write ()
}
if(dirty_temperatures)
{
COPY(block->temperature_1, temp1);
COPY(block->temperature_2, temp2);
block->temperature_1 = temp1;
block->temperature_2 = temp2;
dirty_temperatures = false;
}
if(dirty_occupancies)
{
COPY(block->occupancy, occupancy);
block->occupancy = occupancy;
dirty_occupancies = false;
}
return true;
Expand Down Expand Up @@ -1034,8 +1040,8 @@ void MapExtras::BlockInfo::SquashVeins(df::map_block *mb, t_blockmaterials & mat
{
std::vector <df::block_square_event_mineralst *> veins;
Maps::SortBlockEvents(mb,&veins);
memset(materials,-1,sizeof(materials));
memset(veintype, 0, sizeof(t_veintype));
materials = arr40d_neg1<t_blockmaterials>();
veintype.fill({});

for (uint32_t x = 0;x<16;x++) for (uint32_t y = 0; y< 16;y++)
{
Expand All @@ -1054,7 +1060,7 @@ void MapExtras::BlockInfo::SquashFrozenLiquids(df::map_block *mb, tiletypes40d &
{
std::vector <df::block_square_event_frozen_liquidst *> ices;
Maps::SortBlockEvents(mb,NULL,&ices);
memset(frozen,0,sizeof(frozen));
frozen.fill({});
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
{
for (size_t i = 0; i < ices.size(); i++)
Expand Down Expand Up @@ -1089,7 +1095,7 @@ void MapExtras::BlockInfo::SquashGrass(df::map_block *mb, t_blockmaterials &mate
{
std::vector<df::block_square_event_grassst*> grasses;
Maps::SortBlockEvents(mb, NULL, NULL, NULL, &grasses);
memset(materials,-1,sizeof(materials));
materials = arr40d_neg1<t_blockmaterials>();
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
{
int amount = 0;
Expand Down
24 changes: 10 additions & 14 deletions library/modules/Maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ int32_t Maps::addMaterialSpatter (df::coord pos, int16_t mat, int32_t matg, df::
spatter->mat_type = mat;
spatter->mat_index = matg;
spatter->mat_state = state;
memset(spatter->amount, 0, sizeof(spatter->amount));
spatter->amount.fill({});
spatter->min_temperature = spatter->max_temperature = 60001;

uint16_t melt = matinfo.material->heat.melting_point;
Expand Down Expand Up @@ -876,8 +876,8 @@ int32_t Maps::addItemSpatter (df::coord pos, df::item_type i_type, int16_t i_sub
spatter->mattype = i_subcat1;
spatter->matindex = i_subcat2;
spatter->print_variant = print_variant;
memset(spatter->amount, 0, sizeof(spatter->amount));
memset(spatter->flag, 0, sizeof(spatter->flag));
spatter->amount.fill({});
spatter->flag.fill({});
spatter->min_temperature = spatter->max_temperature = 60001;

if (Items::usesStandardMaterial(i_type))
Expand Down Expand Up @@ -1569,14 +1569,10 @@ void Maps::addBlockColumns(int32_t new_height)

// Copy other potentially important metadata from prior air
// layer
std::memcpy(air_block->lighting, last_air_block->lighting,
sizeof(air_block->lighting));
std::memcpy(air_block->temperature_1, last_air_block->temperature_1,
sizeof(air_block->temperature_1));
std::memcpy(air_block->temperature_2, last_air_block->temperature_2,
sizeof(air_block->temperature_2));
std::memcpy(air_block->region_offset, last_air_block->region_offset,
sizeof(air_block->region_offset));
air_block->lighting = last_air_block->lighting;
air_block->temperature_1 = last_air_block->temperature_1;
air_block->temperature_2 = last_air_block->temperature_2;
air_block->region_offset = last_air_block->region_offset;

// Create tile designations to inform lighting and
// outside markers
Expand All @@ -1598,9 +1594,9 @@ void Maps::addBlockColumns(int32_t new_height)
continue;
}
df::block_column_print_infost* glyphs = new df::block_column_print_infost;
std::ranges::copy(std::array{0,1,2,3}, glyphs->x);
std::ranges::copy(std::array{0,0,0,0}, glyphs->y);
std::ranges::copy(std::array{'e','x','p','^'}, glyphs->tile);
glyphs->x = {0,1,2,3};
glyphs->y = {0,0,0,0};
glyphs->tile = {'e','x','p','^'};
column->unmined_glyphs.push_back(glyphs);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion library/xml
Submodule xml updated 3 files
+2 −1 StructFields.pm
+1 −0 changelog.txt
+1 −1 codegen.pl
13 changes: 7 additions & 6 deletions plugins/remotefortressreader/remotefortressreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,16 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out)
return CR_OK;
}

uint16_t fletcher16(uint8_t const *data, size_t bytes)
uint16_t fletcher16(const void *data_, size_t bytes)
{
auto data = static_cast<const std::byte*>(data_);
uint16_t sum1 = 0xff, sum2 = 0xff;

while (bytes) {
size_t tlen = bytes > 20 ? 20 : bytes;
bytes -= tlen;
do {
sum2 += sum1 += *data++;
sum2 += sum1 += static_cast<uint8_t>(*data++);
} while (--tlen);
sum1 = (sum1 & 0xff) + (sum1 >> 8);
sum2 = (sum2 & 0xff) + (sum2 >> 8);
Expand All @@ -335,7 +336,7 @@ void ConvertDfColor(int16_t index, RemoteFortressReader::ColorDefinition * out)
out->set_blue(gps->uccolor[index][2]);
}

void ConvertDfColor(int16_t in[3], RemoteFortressReader::ColorDefinition * out)
void ConvertDfColor(std::array<int16_t,3>& in, RemoteFortressReader::ColorDefinition * out)
{
int index = in[0] | (8 * in[2]);
ConvertDfColor(index, out);
Expand Down Expand Up @@ -623,7 +624,7 @@ static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in)
for (size_t i = 0; i < world->map.map_blocks.size(); i++)
{
df::map_block * block = world->map.map_blocks[i];
fletcher16((uint8_t*)(block->tiletype), 16 * 16 * sizeof(df::enums::tiletype::tiletype));
fletcher16((block->tiletype).data(), 16 * 16 * sizeof(df::enums::tiletype::tiletype));
}
clock_t end = clock();
double elapsed_secs = double(end - start) / CLOCKS_PER_SEC;
Expand Down Expand Up @@ -654,7 +655,7 @@ bool IsTiletypeChanged(DFCoord pos)
uint16_t hash;
df::map_block * block = Maps::getBlock(pos);
if (block)
hash = fletcher16((uint8_t*)(block->tiletype), 16 * 16 * (sizeof(df::enums::tiletype::tiletype)));
hash = fletcher16((block->tiletype).data(), 16 * 16 * (sizeof(df::enums::tiletype::tiletype)));
else
hash = 0;
if (hashes[pos] != hash)
Expand All @@ -672,7 +673,7 @@ bool IsDesignationChanged(DFCoord pos)
uint16_t hash;
df::map_block * block = Maps::getBlock(pos);
if (block)
hash = fletcher16((uint8_t*)(block->designation), 16 * 16 * (sizeof(df::tile_designation)));
hash = fletcher16((block->designation).data(), 16 * 16 * (sizeof(df::tile_designation)));
else
hash = 0;
if (waterHashes[pos] != hash)
Expand Down
Loading
Loading