Skip to content

Commit

Permalink
Generated from commit 4f70dfd0a0e29722a5182ce7dd75d24298f133b9
Browse files Browse the repository at this point in the history
  • Loading branch information
Pusnow committed May 5, 2024
1 parent 5bf97d4 commit 755314e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)

project(e VERSION 3.3.4)
project(e VERSION 3.3.5)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down
1 change: 1 addition & 0 deletions include/E/E_System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class System : private Log {
timerQueue;
std::unordered_map<UUID, TimerContainer> activeTimer;
std::unordered_set<UUID> activeUUID;
UUID currentUUID = 0;

UUID allocateUUID();
bool deallocateUUID(UUID uuid);
Expand Down
10 changes: 4 additions & 6 deletions include/E/Networking/E_Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class NetworkSystem;
*/
class Packet : public Module::MessageBase {
private:
Packet(UUID uuid, size_t maxSize);
Packet(UUID uuid, size_t size);
std::vector<char> buffer;
size_t bufferSize;
size_t dataSize;

UUID packetID;

Expand Down Expand Up @@ -61,9 +59,9 @@ class Packet : public Module::MessageBase {
Packet &operator=(Packet &&other) noexcept;

/**
* @param maxSize Maximum packet size.
* @param size Packet size.
*/
Packet(size_t maxSize);
Packet(size_t size);

~Packet() override;

Expand Down Expand Up @@ -92,7 +90,7 @@ class Packet : public Module::MessageBase {

/**
* @brief Change the size of this Packet
* The size cannot be larger than the internal buffer.
* The size can be larger than the internal buffer.
* @param size New size.
* @return Actual changed size.
*/
Expand Down
18 changes: 8 additions & 10 deletions src/E/E_System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ UUID System::sendMessage(const ModuleID from, const ModuleID to,
return uuid;
}
UUID System::allocateUUID() {
UUID startID = currentID;
do {
UUID candidate = currentID++;
if (activeUUID.find(candidate) == activeUUID.end()) {
activeUUID.insert(candidate);
return candidate;
}
} while (startID != currentID);
assert(0);
return 0;

UUID candidate = ++currentUUID;
if (activeUUID.find(candidate) == activeUUID.end()) {
activeUUID.insert(candidate);
return candidate;
} else {
assert(0);
}
}

bool System::deallocateUUID(UUID candidate) {
Expand Down
34 changes: 13 additions & 21 deletions src/Networking/E_Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,45 @@ UUID Packet::allocatePacketUUID() {
}
void Packet::freePacketUUID(UUID uuid) { packetUUIDSet.erase(uuid); }

Packet::Packet(UUID uuid, size_t maxSize)
: buffer(maxSize), bufferSize(maxSize), dataSize(maxSize), packetID(uuid) {
Packet::Packet(UUID uuid, size_t size) : buffer(size), packetID(uuid) {

std::fill(this->buffer.begin(), this->buffer.end(), 0);
}

Packet::Packet(const Packet &other)
: buffer(other.buffer), bufferSize(other.bufferSize),
dataSize(other.dataSize), packetID(other.packetID) {}
: buffer(other.buffer), packetID(other.packetID) {}

Packet::Packet(Packet &&other) noexcept
: buffer(std::move(other.buffer)), bufferSize(other.bufferSize),
dataSize(other.dataSize), packetID(other.packetID) {
other.dataSize = 0;
: buffer(std::move(other.buffer)), packetID(other.packetID) {
other.buffer.clear();
}

Packet &Packet::operator=(const Packet &other) {
buffer = other.buffer;
bufferSize = other.bufferSize;
dataSize = other.dataSize;
packetID = other.packetID;
return *this;
}

Packet &Packet::operator=(Packet &&other) noexcept {
buffer = std::move(other.buffer);
bufferSize = std::move(other.bufferSize);
dataSize = std::move(other.dataSize);
packetID = std::move(other.packetID);
return *this;
}

Packet::Packet(size_t maxSize) : Packet(allocatePacketUUID(), maxSize) {}
Packet::Packet(size_t size) : Packet(allocatePacketUUID(), size) {}

Packet::~Packet() { freePacketUUID(this->packetID); }

Packet Packet::clone() const {

Packet pkt(this->bufferSize);
pkt.setSize(this->dataSize);
Packet pkt(this->buffer.size());
pkt.buffer = this->buffer;
return pkt;
}

size_t Packet::writeData(size_t offset, const void *data, size_t length) {
size_t actual_offset = std::min(offset, dataSize);
size_t actual_write = std::min(length, dataSize - actual_offset);
size_t actual_offset = std::min(offset, buffer.size());
size_t actual_write = std::min(length, buffer.size() - actual_offset);

if (actual_write == 0)
return 0;
Expand All @@ -83,8 +75,8 @@ size_t Packet::writeData(size_t offset, const void *data, size_t length) {
return actual_write;
}
size_t Packet::readData(size_t offset, void *data, size_t length) const {
size_t actual_offset = std::min(offset, dataSize);
size_t actual_read = std::min(length, dataSize - actual_offset);
size_t actual_offset = std::min(offset, buffer.size());
size_t actual_read = std::min(length, buffer.size() - actual_offset);

if (actual_read == 0)
return 0;
Expand All @@ -94,10 +86,10 @@ size_t Packet::readData(size_t offset, void *data, size_t length) const {
return actual_read;
}
size_t Packet::setSize(size_t size) {
this->dataSize = std::min(size, this->bufferSize);
return this->dataSize;
buffer.resize(size);
return buffer.size();
}
size_t Packet::getSize() const { return this->dataSize; }
size_t Packet::getSize() const { return buffer.size(); }

UUID Packet::getUUID() const { return this->packetID; }

Expand Down

0 comments on commit 755314e

Please sign in to comment.