Can now clean bullets off the forest.
This commit is contained in:
parent
7e98eeb852
commit
7d46536acc
@ -1167,7 +1167,7 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
|
|||||||
return pck;
|
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;
|
std::vector<char*> lsPck;
|
||||||
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
|
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
|
||||||
end = 0;
|
end = 0;
|
||||||
@ -1207,7 +1207,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
|
|||||||
if (end < 0)
|
if (end < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
cursor = (char*)memchr(next, '\r', end);
|
cursor = (char*)std::move(memchr(next, '\r', end));
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
next = 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));
|
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
if (!outbuf) {
|
lsPck.push_back(std::move(last));
|
||||||
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);
|
cursor += sizeof(uint32_t);
|
||||||
last = cursor;
|
last = cursor;
|
||||||
next = cursor + 1;
|
next = cursor + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (!outbuf)
|
buf->tmp = std::move(last);
|
||||||
buf->tmp = last;
|
cursor = std::move(&buf->ptr[len]);
|
||||||
cursor = &buf->ptr[len];
|
|
||||||
next = cursor + 1;
|
next = cursor + 1;
|
||||||
break;
|
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;
|
std::vector<char*> lsPck;
|
||||||
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
|
int len = buf->tmp ? buf->tmp - buf->ptr : 0,
|
||||||
end = 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));
|
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
if (!outbuf) {
|
|
||||||
lsPck.push_back(last);
|
lsPck.push_back(last);
|
||||||
cursor += sizeof(uint32_t);
|
cursor += sizeof(uint32_t);
|
||||||
last = cursor;
|
last = cursor;
|
||||||
next = cursor + 1;
|
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 {
|
else {
|
||||||
if (!outbuf)
|
|
||||||
buf->tmp = last;
|
buf->tmp = last;
|
||||||
cursor = &buf->ptr[len];
|
cursor = &buf->ptr[len];
|
||||||
next = cursor + 1;
|
next = cursor + 1;
|
||||||
|
@ -193,8 +193,8 @@ namespace netprot {
|
|||||||
template <class T> void sendPack(SOCKET sock, T* pack, Buffer* buf);
|
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);
|
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*> recvPacks(SOCKET sock, Buffer* buf);
|
||||||
std::vector<char*> recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* oufbuf = nullptr);
|
std::vector<char*> recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from);
|
||||||
|
|
||||||
/* Templates */
|
/* Templates */
|
||||||
|
|
||||||
|
@ -224,7 +224,8 @@ void Server::Run() {
|
|||||||
Timestamp last = 0;
|
Timestamp last = 0;
|
||||||
std::vector<Chat*> chatlog;
|
std::vector<Chat*> chatlog;
|
||||||
std::vector<ChunkMod*> chunkdiffs;
|
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;
|
std::vector<BulletAdd*> netbull;
|
||||||
|
|
||||||
Chat* startchat = new Chat();
|
Chat* startchat = new Chat();
|
||||||
@ -335,18 +336,20 @@ void Server::Run() {
|
|||||||
}
|
}
|
||||||
netbull.clear();
|
netbull.clear();
|
||||||
|
|
||||||
for (auto& bull : bullets) {
|
for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
|
||||||
ChunkMod* cmod = nullptr;
|
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)
|
if (cmod)
|
||||||
chunkdiffs.emplace_back(std::move(cmod));
|
chunkdiffs.emplace_back(cmod);
|
||||||
outbox_bullets.emplace_back(std::move(bull));
|
bullit.push_back(bull);
|
||||||
|
delete bullet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto gtfo : outbox_bullets)
|
for (auto& bull: bullit)
|
||||||
delete gtfo;
|
bullets.erase(bull);
|
||||||
outbox_bullets.clear();
|
bullit.clear();
|
||||||
|
|
||||||
for (auto& chat : chatlog) {
|
for (auto& chat : chatlog) {
|
||||||
Log(chat->mess, false, false);
|
Log(chat->mess, false, false);
|
||||||
@ -362,10 +365,6 @@ void Server::Run() {
|
|||||||
delete chmo;
|
delete chmo;
|
||||||
}
|
}
|
||||||
chunkdiffs.clear();
|
chunkdiffs.clear();
|
||||||
|
|
||||||
//for (auto& bull : outbox_bullets)
|
|
||||||
// delete bull;
|
|
||||||
//outbox_bullets.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Chat end;
|
Chat end;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user