Can now clean bullets off the forest.

This commit is contained in:
MarcEricMartel 2023-12-08 04:31:10 -05:00
parent 7e98eeb852
commit 7d46536acc
3 changed files with 65 additions and 86 deletions

View File

@ -1167,7 +1167,7 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
return pck;
}
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf) {
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
std::vector<char*> lsPck;
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
end = 0;
@ -1207,7 +1207,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
if (end < 0)
break;
cursor = (char*)memchr(next, '\r', end);
cursor = (char*)std::move(memchr(next, '\r', end));
if (cursor) {
next = cursor;
@ -1215,25 +1215,15 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
if (cmp == 0) {
if (!outbuf) {
lsPck.push_back(last);
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
else {
memcpy(&outbuf->ptr[cursor - last], last, cursor - last);
lsPck.push_back(&outbuf->ptr[cursor - last]);
lsPck.push_back(std::move(last));
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
}
}
else {
if (!outbuf)
buf->tmp = last;
cursor = &buf->ptr[len];
buf->tmp = std::move(last);
cursor = std::move(&buf->ptr[len]);
next = cursor + 1;
break;
};
@ -1241,7 +1231,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
}
}
std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* outbuf) {
std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from) {
std::vector<char*> lsPck;
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
end = 0;
@ -1291,23 +1281,13 @@ std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
if (cmp == 0) {
if (!outbuf) {
lsPck.push_back(last);
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
else {
memcpy(&outbuf->ptr[cursor - last], last, cursor - last);
lsPck.push_back(&outbuf->ptr[cursor - last]);
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
}
}
else {
if (!outbuf)
buf->tmp = last;
cursor = &buf->ptr[len];
next = cursor + 1;

View File

@ -193,8 +193,8 @@ namespace netprot {
template <class T> void sendPack(SOCKET sock, T* pack, Buffer* buf);
template <class T> void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad);
std::vector<char*> recvPacks(SOCKET sock, Buffer* buf, Buffer* oufbuf = nullptr);
std::vector<char*> recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* oufbuf = nullptr);
std::vector<char*> recvPacks(SOCKET sock, Buffer* buf);
std::vector<char*> recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from);
/* Templates */

View File

@ -224,7 +224,8 @@ void Server::Run() {
Timestamp last = 0;
std::vector<Chat*> chatlog;
std::vector<ChunkMod*> chunkdiffs;
std::vector<Bullet*> bullets, outbox_bullets;
std::vector<Bullet*> bullets;
std::vector<std::vector<Bullet*>::iterator> bullit;
std::vector<BulletAdd*> netbull;
Chat* startchat = new Chat();
@ -335,18 +336,20 @@ void Server::Run() {
}
netbull.clear();
for (auto& bull : bullets) {
for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
ChunkMod* cmod = nullptr;
if (bull->Update(m_world, (1. / 60.), 20, m_players, &cmod)) {
Bullet* bullet = *bull;
if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) {
if (cmod)
chunkdiffs.emplace_back(std::move(cmod));
outbox_bullets.emplace_back(std::move(bull));
chunkdiffs.emplace_back(cmod);
bullit.push_back(bull);
delete bullet;
}
}
for (auto gtfo : outbox_bullets)
delete gtfo;
outbox_bullets.clear();
for (auto& bull: bullit)
bullets.erase(bull);
bullit.clear();
for (auto& chat : chatlog) {
Log(chat->mess, false, false);
@ -362,10 +365,6 @@ void Server::Run() {
delete chmo;
}
chunkdiffs.clear();
//for (auto& bull : outbox_bullets)
// delete bull;
//outbox_bullets.clear();
}
Chat end;