일단 오늘은 이걸로..
This commit is contained in:
@@ -8,12 +8,12 @@
|
||||
#include "socket/wsa_manager.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/snowflake.h"
|
||||
#include "vulkan_engine/asset/object/model.h"
|
||||
#include "utils/utils.h"
|
||||
#include "vulkan_engine/asset/object/model.h"
|
||||
|
||||
#define LISTENIP "::"
|
||||
#define LISTENPORT 9010
|
||||
#define TICKRATE 30
|
||||
#define TICKRATE 60
|
||||
constexpr double TICKDELAY = (1 / TICKRATE);
|
||||
|
||||
std::uint8_t CLIENTID = 0;
|
||||
@@ -24,7 +24,8 @@ std::list<std::shared_ptr<Network::Socket>> CLIENTS;
|
||||
std::mutex CLIENTS_MUTEX;
|
||||
|
||||
void EchoClient(utils::ThreadPool* tp, Network::IOCP* iocp,
|
||||
std::shared_ptr<Network::Socket> NewSock, Network::Address NewAddr) {
|
||||
std::shared_ptr<Network::Socket> NewSock,
|
||||
Network::Address NewAddr) {
|
||||
if (NewSock->sock == 0) return;
|
||||
std::future<std::list<char>> result;
|
||||
Packet::Header header;
|
||||
@@ -32,7 +33,7 @@ void EchoClient(utils::ThreadPool* tp, Network::IOCP* iocp,
|
||||
|
||||
result = iocp->recv(NewSock, 14);
|
||||
recv_data = utils::CvtListToVector(result.get());
|
||||
|
||||
|
||||
header.Deserialize(recv_data);
|
||||
|
||||
result = iocp->recv(NewSock, header.body_length);
|
||||
@@ -79,6 +80,16 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
}
|
||||
CLIENTS_MUTEX.unlock();
|
||||
|
||||
for (auto it = MODELS.begin(); it != MODELS.end();) {
|
||||
auto& model = it->second;
|
||||
|
||||
if (model.shouldBeDestroyed) {
|
||||
it = MODELS.erase(it);
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
for (auto it = MODELS.begin(); it != MODELS.end();) {
|
||||
auto& model = it->second;
|
||||
|
||||
@@ -89,12 +100,7 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
}
|
||||
|
||||
if (model.lifespan <= 0.f) {
|
||||
it = MODELS.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (model.shouldBeDestroyed) {
|
||||
it = MODELS.erase(it);
|
||||
it->second.shouldBeDestroyed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -111,7 +117,13 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
std::vector<char> send_data;
|
||||
auto model_serialized = model.second.Serialize();
|
||||
Packet::Header header;
|
||||
header.opcode = Packet::Opcode::UPDATEMODEL;
|
||||
|
||||
if (model.second.shouldBeDestroyed) {
|
||||
header.opcode = Packet::Opcode::DESPAWNMODEL;
|
||||
} else {
|
||||
header.opcode = Packet::Opcode::UPDATEMODEL;
|
||||
}
|
||||
|
||||
header.timestamp = glfwGetTime();
|
||||
header.body_length = model_serialized.size();
|
||||
auto header_serialized = header.Serialize();
|
||||
@@ -119,14 +131,16 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
header_serialized.end());
|
||||
send_data.insert(send_data.end(), model_serialized.begin(),
|
||||
model_serialized.end());
|
||||
if (!model.second.needsUpdate && !needs_all_update) {
|
||||
if (!model.second.needsUpdate && !needs_all_update &&
|
||||
!model.second.shouldBeDestroyed) {
|
||||
continue;
|
||||
}
|
||||
model.second.needsUpdate = false;
|
||||
if (iocp->send(client, send_data) == -1) {
|
||||
client->sock = 0;
|
||||
}
|
||||
spdlog::debug("server-side updated : [{}:{}]", model.second.name, model.second.ID.snowflake);
|
||||
// spdlog::debug("server-side updated : [{}:{}]", model.second.name,
|
||||
// model.second.ID.snowflake);
|
||||
}
|
||||
}
|
||||
CLIENTS_MUTEX.unlock();
|
||||
|
||||
Reference in New Issue
Block a user