diff --git a/client/globalLobby/GlobalLobbyLoginWindow.cpp b/client/globalLobby/GlobalLobbyLoginWindow.cpp index bf7a83753..7403b206a 100644 --- a/client/globalLobby/GlobalLobbyLoginWindow.cpp +++ b/client/globalLobby/GlobalLobbyLoginWindow.cpp @@ -35,7 +35,7 @@ GlobalLobbyLoginWindow::GlobalLobbyLoginWindow() pos.w = 200; pos.h = 200; - background = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); + filledBackground = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); labelTitle = std::make_shared( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.login.title")); labelUsername = std::make_shared( 10, 45, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("vcmi.lobby.login.username")); backgroundUsername = std::make_shared(Rect(10, 70, 180, 20), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64)); @@ -44,7 +44,7 @@ GlobalLobbyLoginWindow::GlobalLobbyLoginWindow() buttonClose = std::make_shared(Point(126, 160), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); }); labelStatus = std::make_shared( "", Rect(15, 95, 175, 60), 1, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE); - background->playerColored(PlayerColor(1)); + filledBackground->playerColored(PlayerColor(1)); inputUsername->setText(settings["lobby"]["displayName"].String()); inputUsername->cb += [this](const std::string & text) { diff --git a/client/globalLobby/GlobalLobbyLoginWindow.h b/client/globalLobby/GlobalLobbyLoginWindow.h index 31bcd5015..54bccc182 100644 --- a/client/globalLobby/GlobalLobbyLoginWindow.h +++ b/client/globalLobby/GlobalLobbyLoginWindow.h @@ -20,7 +20,7 @@ class CButton; class GlobalLobbyLoginWindow : public CWindowObject { - std::shared_ptr background; + std::shared_ptr filledBackground; std::shared_ptr labelTitle; std::shared_ptr labelUsername; std::shared_ptr labelStatus; diff --git a/client/globalLobby/GlobalLobbyServerSetup.cpp b/client/globalLobby/GlobalLobbyServerSetup.cpp index 8b64e2377..eb566390f 100644 --- a/client/globalLobby/GlobalLobbyServerSetup.cpp +++ b/client/globalLobby/GlobalLobbyServerSetup.cpp @@ -31,7 +31,7 @@ GlobalLobbyServerSetup::GlobalLobbyServerSetup() pos.w = 284; pos.h = 340; - background = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); + filledBackground = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); labelTitle = std::make_shared( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.create")); labelPlayerLimit = std::make_shared( pos.w / 2, 48, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.players.limit")); labelRoomType = std::make_shared( pos.w / 2, 108, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.type")); @@ -75,7 +75,7 @@ GlobalLobbyServerSetup::GlobalLobbyServerSetup() buttonCreate = std::make_shared(Point(10, 300), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onCreate(); }); buttonClose = std::make_shared(Point(210, 300), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); }); - background->playerColored(PlayerColor(1)); + filledBackground->playerColored(PlayerColor(1)); updateDescription(); center(); diff --git a/client/globalLobby/GlobalLobbyServerSetup.h b/client/globalLobby/GlobalLobbyServerSetup.h index 7f49bb130..f8fa09d34 100644 --- a/client/globalLobby/GlobalLobbyServerSetup.h +++ b/client/globalLobby/GlobalLobbyServerSetup.h @@ -19,7 +19,7 @@ class CToggleGroup; class GlobalLobbyServerSetup : public CWindowObject { - std::shared_ptr background; + std::shared_ptr filledBackground; std::shared_ptr labelTitle; std::shared_ptr labelPlayerLimit; diff --git a/client/globalLobby/GlobalLobbyWidget.h b/client/globalLobby/GlobalLobbyWidget.h index 4942add0a..61caaaa21 100644 --- a/client/globalLobby/GlobalLobbyWidget.h +++ b/client/globalLobby/GlobalLobbyWidget.h @@ -24,7 +24,7 @@ class GlobalLobbyWidget : public InterfaceObjectConfigurable std::shared_ptr buildRoomList(const JsonNode &) const; public: - GlobalLobbyWidget(GlobalLobbyWindow * window); + explicit GlobalLobbyWidget(GlobalLobbyWindow * window); std::shared_ptr getAccountNameLabel(); std::shared_ptr getMessageInput(); diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index 4124bd818..f0a6334f8 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -72,10 +72,6 @@ JsonNode::JsonNode(JsonType Type) setType(Type); } -JsonNode::JsonNode(const uint8_t *data, size_t datasize) - :JsonNode(reinterpret_cast(data), datasize) -{} - JsonNode::JsonNode(const std::byte *data, size_t datasize) :JsonNode(reinterpret_cast(data), datasize) {} diff --git a/lib/JsonNode.h b/lib/JsonNode.h index bd9de7886..75f9128b2 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -51,7 +51,6 @@ public: JsonNode(JsonType Type = JsonType::DATA_NULL); //Create tree from Json-formatted input explicit JsonNode(const char * data, size_t datasize); - explicit JsonNode(const uint8_t * data, size_t datasize); explicit JsonNode(const std::byte * data, size_t datasize); //Create tree from JSON file explicit JsonNode(const JsonPath & fileURI); diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index b34addee5..222ed2364 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -23,9 +23,13 @@ protected: public: CLoaderBase(IBinaryReader * r): reader(r){}; - inline int read(void * data, unsigned size) + inline void read(void * data, unsigned size, bool reverseEndianess) { - return reader->read(data, size); + auto bytePtr = reinterpret_cast(data); + + reader->read(bytePtr, size); + if(reverseEndianess) + std::reverse(bytePtr, bytePtr + size); }; }; @@ -170,11 +174,7 @@ public: template < class T, typename std::enable_if < std::is_fundamental::value && !std::is_same::value, int >::type = 0 > void load(T &data) { - unsigned length = sizeof(data); - char * dataPtr = reinterpret_cast(&data); - this->read(dataPtr,length); - if(reverseEndianess) - std::reverse(dataPtr, dataPtr + length); + this->read(static_cast(&data), sizeof(data), reverseEndianess); } template < typename T, typename std::enable_if < is_serializeable::value, int >::type = 0 > @@ -439,7 +439,7 @@ public: { ui32 length = readAndCheckLength(); data.resize(length); - this->read((void*)data.c_str(),length); + this->read(static_cast(data.data()), length, false); } template diff --git a/lib/serializer/BinarySerializer.h b/lib/serializer/BinarySerializer.h index 9f465e539..07d152ad3 100644 --- a/lib/serializer/BinarySerializer.h +++ b/lib/serializer/BinarySerializer.h @@ -23,9 +23,9 @@ protected: public: CSaverBase(IBinaryWriter * w): writer(w){}; - inline int write(const void * data, unsigned size) + inline void write(const void * data, unsigned size) { - return writer->write(data, size); + writer->write(reinterpret_cast(data), size); }; }; @@ -145,7 +145,7 @@ public: void save(const T &data) { // save primitive - simply dump binary data to output - this->write(&data,sizeof(data)); + this->write(static_cast(&data), sizeof(data)); } template < typename T, typename std::enable_if < std::is_enum::value, int >::type = 0 > @@ -312,7 +312,7 @@ public: void save(const std::string &data) { save(ui32(data.length())); - this->write(data.c_str(),(unsigned int)data.size()); + this->write(static_cast(data.data()), data.size()); } template void save(const std::pair &data) diff --git a/lib/serializer/CLoadFile.cpp b/lib/serializer/CLoadFile.cpp index 2e50fa6c1..ef43b8e27 100644 --- a/lib/serializer/CLoadFile.cpp +++ b/lib/serializer/CLoadFile.cpp @@ -21,7 +21,7 @@ CLoadFile::CLoadFile(const boost::filesystem::path & fname, ESerializationVersio //must be instantiated in .cpp file for access to complete types of all member fields CLoadFile::~CLoadFile() = default; -int CLoadFile::read(void * data, unsigned size) +int CLoadFile::read(std::byte * data, unsigned size) { sfile->read(reinterpret_cast(data), size); return size; @@ -92,7 +92,7 @@ void CLoadFile::clear() void CLoadFile::checkMagicBytes(const std::string &text) { std::string loaded = text; - read((void *)loaded.data(), static_cast(text.length())); + read(reinterpret_cast(loaded.data()), text.length()); if(loaded != text) throw std::runtime_error("Magic bytes doesn't match!"); } diff --git a/lib/serializer/CLoadFile.h b/lib/serializer/CLoadFile.h index 405c1f99c..800872038 100644 --- a/lib/serializer/CLoadFile.h +++ b/lib/serializer/CLoadFile.h @@ -23,7 +23,7 @@ public: CLoadFile(const boost::filesystem::path & fname, ESerializationVersion minimalVersion = ESerializationVersion::CURRENT); //throws! virtual ~CLoadFile(); - int read(void * data, unsigned size) override; //throws! + int read(std::byte * data, unsigned size) override; //throws! void openNextFile(const boost::filesystem::path & fname, ESerializationVersion minimalVersion); //throws! void clear(); diff --git a/lib/serializer/CMemorySerializer.cpp b/lib/serializer/CMemorySerializer.cpp index 39a647335..fd7346793 100644 --- a/lib/serializer/CMemorySerializer.cpp +++ b/lib/serializer/CMemorySerializer.cpp @@ -12,7 +12,7 @@ VCMI_LIB_NAMESPACE_BEGIN -int CMemorySerializer::read(void * data, unsigned size) +int CMemorySerializer::read(std::byte * data, unsigned size) { if(buffer.size() < readPos + size) throw std::runtime_error(boost::str(boost::format("Cannot read past the buffer (accessing index %d, while size is %d)!") % (readPos + size - 1) % buffer.size())); @@ -22,7 +22,7 @@ int CMemorySerializer::read(void * data, unsigned size) return size; } -int CMemorySerializer::write(const void * data, unsigned size) +int CMemorySerializer::write(const std::byte * data, unsigned size) { auto oldSize = buffer.size(); //and the pos to write from buffer.resize(oldSize + size); diff --git a/lib/serializer/CMemorySerializer.h b/lib/serializer/CMemorySerializer.h index 586220724..510012d29 100644 --- a/lib/serializer/CMemorySerializer.h +++ b/lib/serializer/CMemorySerializer.h @@ -25,8 +25,8 @@ public: BinaryDeserializer iser; BinarySerializer oser; - int read(void * data, unsigned size) override; //throws! - int write(const void * data, unsigned size) override; + int read(std::byte * data, unsigned size) override; //throws! + int write(const std::byte * data, unsigned size) override; CMemorySerializer(); diff --git a/lib/serializer/CSaveFile.cpp b/lib/serializer/CSaveFile.cpp index e575a88a3..d406342b4 100644 --- a/lib/serializer/CSaveFile.cpp +++ b/lib/serializer/CSaveFile.cpp @@ -21,9 +21,9 @@ CSaveFile::CSaveFile(const boost::filesystem::path &fname) //must be instantiated in .cpp file for access to complete types of all member fields CSaveFile::~CSaveFile() = default; -int CSaveFile::write(const void * data, unsigned size) +int CSaveFile::write(const std::byte * data, unsigned size) { - sfile->write((char *)data,size); + sfile->write(reinterpret_cast(data), size); return size; } @@ -66,7 +66,7 @@ void CSaveFile::clear() void CSaveFile::putMagicBytes(const std::string &text) { - write(text.c_str(), static_cast(text.length())); + write(reinterpret_cast(text.c_str()), text.length()); } VCMI_LIB_NAMESPACE_END diff --git a/lib/serializer/CSaveFile.h b/lib/serializer/CSaveFile.h index f1b823bf2..857b7f159 100644 --- a/lib/serializer/CSaveFile.h +++ b/lib/serializer/CSaveFile.h @@ -23,7 +23,7 @@ public: CSaveFile(const boost::filesystem::path &fname); //throws! ~CSaveFile(); - int write(const void * data, unsigned size) override; + int write(const std::byte * data, unsigned size) override; void openNextFile(const boost::filesystem::path &fname); //throws! void clear(); diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index 6ab715d3c..d0f90c758 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -175,14 +175,14 @@ struct VectorizedIDType class DLL_LINKAGE IBinaryReader : public virtual CSerializer { public: - virtual int read(void * data, unsigned size) = 0; + virtual int read(std::byte * data, unsigned size) = 0; }; /// Base class for serializers class DLL_LINKAGE IBinaryWriter : public virtual CSerializer { public: - virtual int write(const void * data, unsigned size) = 0; + virtual int write(const std::byte * data, unsigned size) = 0; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/serializer/Connection.cpp b/lib/serializer/Connection.cpp index 33a25363e..cc6c83719 100644 --- a/lib/serializer/Connection.cpp +++ b/lib/serializer/Connection.cpp @@ -24,7 +24,7 @@ class DLL_LINKAGE ConnectionPackWriter final : public IBinaryWriter public: std::vector buffer; - int write(const void * data, unsigned size) final; + int write(const std::byte * data, unsigned size) final; }; class DLL_LINKAGE ConnectionPackReader final : public IBinaryReader @@ -33,25 +33,21 @@ public: const std::vector * buffer; size_t position; - int read(void * data, unsigned size) final; + int read(std::byte * data, unsigned size) final; }; -int ConnectionPackWriter::write(const void * data, unsigned size) +int ConnectionPackWriter::write(const std::byte * data, unsigned size) { - const std::byte * begin_ptr = static_cast(data); - const std::byte * end_ptr = begin_ptr + size; - buffer.insert(buffer.end(), begin_ptr, end_ptr); + buffer.insert(buffer.end(), data, data + size); return size; } -int ConnectionPackReader::read(void * data, unsigned size) +int ConnectionPackReader::read(std::byte * data, unsigned size) { if (position + size > buffer->size()) throw std::runtime_error("End of file reached when reading received network pack!"); - std::byte * begin_ptr = static_cast(data); - - std::copy_n(buffer->begin() + position, size, begin_ptr); + std::copy_n(buffer->begin() + position, size, data); position += size; return size; } diff --git a/lib/serializer/Connection.h b/lib/serializer/Connection.h index 067ab415d..5e18bbbf7 100644 --- a/lib/serializer/Connection.h +++ b/lib/serializer/Connection.h @@ -46,7 +46,7 @@ public: std::string uuid; int connectionID; - CConnection(std::weak_ptr networkConnection); + explicit CConnection(std::weak_ptr networkConnection); ~CConnection(); void sendPack(const CPack * pack); diff --git a/lobby/LobbyServer.cpp b/lobby/LobbyServer.cpp index 5cf741e7e..551425025 100644 --- a/lobby/LobbyServer.cpp +++ b/lobby/LobbyServer.cpp @@ -205,10 +205,10 @@ void LobbyServer::onNewConnection(const NetworkConnectionPtr & connection) void LobbyServer::onDisconnected(const NetworkConnectionPtr & connection, const std::string & errorMessage) { - if (activeAccounts.count(connection)) + if(activeAccounts.count(connection)) database->setAccountOnline(activeAccounts.at(connection), false); - if (activeGameRooms.count(connection)) + if(activeGameRooms.count(connection)) database->setGameRoomStatus(activeGameRooms.at(connection), LobbyRoomState::CLOSED); // NOTE: lost connection can be in only one of these lists (or in none of them)