diff --git a/src/fileio/fileio.hpp b/src/fileio/fileio.hpp index 766b235d..1e587a14 100644 --- a/src/fileio/fileio.hpp +++ b/src/fileio/fileio.hpp @@ -40,6 +40,11 @@ struct array_value_type { using type = T; }; +template +struct array_value_type, D1>> { + using type = T; +}; + template void writeArray(std::ostream& to, const T& array, int width, int height) { using int_type = decltype(typename array_value_type::type() + 1); diff --git a/src/scenario/outdoors.hpp b/src/scenario/outdoors.hpp index 0f1314d5..e3cc6f82 100644 --- a/src/scenario/outdoors.hpp +++ b/src/scenario/outdoors.hpp @@ -34,6 +34,9 @@ enum eAmbientSound { AMBIENT_CUSTOM, }; +template +using bitmap = std::array, x>; + class cOutdoors : public cArea { cScenario* scenario; public: @@ -68,8 +71,8 @@ public: std::array wandering_locs; std::string comment; std::vector spec_strs; - bool special_spot[48][48]; - bool roads[48][48]; + bitmap<48, 48> special_spot; + bitmap<48, 48> roads; eAmbientSound ambient_sound = AMBIENT_NONE; snd_num_t out_sound; int bg_out, bg_fight, bg_town, bg_dungeon; diff --git a/src/universe/party.cpp b/src/universe/party.cpp index f4413fed..265c95bd 100644 --- a/src/universe/party.cpp +++ b/src/universe/party.cpp @@ -37,7 +37,7 @@ cParty::cParty(ePartyPreset party_preset) { out_loc.y = 84; in_boat = -1; in_horse = -1; - memset(stuff_done, 0, sizeof(stuff_done)); + wipe_sdfs(); std::fill(magic_ptrs.begin(), magic_ptrs.end(), 0); for(int i = 0; i < 10; i++) out_c[i].exists = false; @@ -53,6 +53,7 @@ cParty::cParty(const cParty& other) , age(other.age) , gold(other.gold) , food(other.food) + , stuff_done(other.stuff_done) , hostiles_present(other.hostiles_present) , easy_mode(other.easy_mode) , less_wm(other.less_wm) @@ -101,7 +102,6 @@ cParty::cParty(const cParty& other) , campaign_flags(other.campaign_flags) , pointers(other.pointers) { - memcpy(stuff_done, other.stuff_done, sizeof(stuff_done)); for(int i = 0; i < 6; i++) { adven[i].reset(new cPlayer(*this, *other.adven[i])); } @@ -121,6 +121,7 @@ void cParty::swap(cParty& other) { std::swap(age, other.age); std::swap(gold, other.gold); std::swap(food, other.food); + std::swap(stuff_done, other.stuff_done); std::swap(hostiles_present, other.hostiles_present); std::swap(easy_mode, other.easy_mode); std::swap(less_wm, other.less_wm); @@ -170,11 +171,6 @@ void cParty::swap(cParty& other) { std::swap(scen_played, other.scen_played); std::swap(campaign_flags, other.campaign_flags); std::swap(pointers, other.pointers); - unsigned char temp_sdf[350][50]; - memcpy(temp_sdf, stuff_done, sizeof(stuff_done)); - memcpy(stuff_done, other.stuff_done, sizeof(stuff_done)); - memcpy(other.stuff_done, temp_sdf, sizeof(stuff_done)); - unsigned short temp_setup[4][64][64]; for(size_t i = 0; i < adven.size(); i++) { std::swap(adven[i], other.adven[i]); } @@ -908,7 +904,7 @@ void cParty::readFrom(const cTagFile& file) { left_in = -1; } - memset(stuff_done, 0, sizeof(stuff_done)); + wipe_sdfs(); for(size_t i = 0; i < page["SDF"].size(); i++) { size_t x, y, val; page["SDF"] >> x >> y >> val; @@ -1188,6 +1184,12 @@ bool cParty::sd_legit(short a, short b) const { return false; } +void cParty::wipe_sdfs() { + for(auto& col : stuff_done) { + col.fill(0); + } +} + bool operator==(const cParty::cConvers& one, const cParty::cConvers& two) { if(one.who_said != two.who_said) return false; if(one.in_town != two.in_town) return false; diff --git a/src/universe/party.hpp b/src/universe/party.hpp index e066c067..d2336c53 100644 --- a/src/universe/party.hpp +++ b/src/universe/party.hpp @@ -36,13 +36,16 @@ namespace legacy { struct setup_save_type; }; +template +using array2d = std::array, x>; + struct campaign_flag_type{ - unsigned char idx[25][25]; + array2d idx{}; private: using idx_array = decltype(idx); public: - static const int x_max = std::extent::value - 1; - static const int y_max = std::extent::value - 1; + static const int x_max = std::tuple_size::value; + static const int y_max = std::tuple_size::value; }; struct job_bank_t { @@ -87,7 +90,7 @@ public: unsigned long age; unsigned short gold; unsigned short food; - unsigned char stuff_done[350][50]; + array2d stuff_done; // These used to be stored as magic SDFs unsigned char hostiles_present; bool easy_mode = false, less_wm = false; @@ -138,8 +141,8 @@ private: std::map> pointers; using sd_array = decltype(stuff_done); public: - static const int sdx_max = std::extent::value - 1; - static const int sdy_max = std::extent::value - 1; + static const int sdx_max = std::tuple_size::value; + static const int sdy_max = std::tuple_size::value; void set_ptr(unsigned short p, unsigned short sdfx, unsigned short sdfy); void force_ptr(unsigned short p, unsigned short val); @@ -211,6 +214,7 @@ public: void swap_pcs(size_t a, size_t b); bool sd_legit(short a, short b) const; + void wipe_sdfs(); auto begin() -> boost::indirect_iterator { return boost::make_indirect_iterator(adven.begin()); diff --git a/src/universe/universe.cpp b/src/universe/universe.cpp index 74972926..f75a653d 100644 --- a/src/universe/universe.cpp +++ b/src/universe/universe.cpp @@ -1018,8 +1018,8 @@ void cUniverse::swap(cUniverse& other) { } void cCurOut::copy(const cCurOut& other) { - memcpy(out, other.out, sizeof(out)); - memcpy(out_e, other.out_e, sizeof(out_e)); + out = other.out; + out_e = other.out_e; } void cCurOut::swap(cCurOut& other) { @@ -1381,7 +1381,7 @@ void cUniverse::enter_scenario(const std::string& name) { using namespace std::placeholders; party.age = 0; - memset(party.stuff_done, 0, sizeof(party.stuff_done)); + party.wipe_sdfs(); party.light_level = 0; party.outdoor_corner = scenario.out_sec_start; party.i_w_c = {0, 0}; diff --git a/src/universe/universe.hpp b/src/universe/universe.hpp index 5ba63585..ed29f21b 100644 --- a/src/universe/universe.hpp +++ b/src/universe/universe.hpp @@ -144,8 +144,8 @@ class cCurOut { public: static const int max_dim = 96; static const int half_dim = max_dim / 2; - ter_num_t out[max_dim][max_dim]; - unsigned char out_e[max_dim][max_dim]; + array2d out; + array2d out_e; // These take global coords (ie 0..95) bool is_spot(int x, int y) const; @@ -154,7 +154,7 @@ public: void import_legacy(legacy::out_info_type& old); - typedef ter_num_t arr_96[max_dim]; + using arr_96 = decltype(out)::value_type; arr_96& operator [] (size_t i); const arr_96& operator [] (size_t i) const; ter_num_t& operator [] (location loc);