Подгонка
This commit is contained in:
@@ -131,6 +131,7 @@ coro<std::unique_ptr<Net::AsyncSocket>> ServerSession::asyncInitGameProtocol(asi
|
|||||||
|
|
||||||
void ServerSession::shutdown(EnumDisconnect type) {
|
void ServerSession::shutdown(EnumDisconnect type) {
|
||||||
IsGoingShutdown = true;
|
IsGoingShutdown = true;
|
||||||
|
Socket->closeRead();
|
||||||
Net::Packet packet;
|
Net::Packet packet;
|
||||||
packet << (uint8_t) ToServer::L1::System
|
packet << (uint8_t) ToServer::L1::System
|
||||||
<< (uint8_t) ToServer::L2System::Disconnect
|
<< (uint8_t) ToServer::L2System::Disconnect
|
||||||
@@ -206,11 +207,11 @@ coro<> ServerSession::run() {
|
|||||||
co_await readPacket(*Socket);
|
co_await readPacket(*Socket);
|
||||||
}
|
}
|
||||||
} catch(const std::exception &exc) {
|
} catch(const std::exception &exc) {
|
||||||
if(const auto *errc = dynamic_cast<const boost::system::system_error*>(&exc);
|
// if(const auto *errc = dynamic_cast<const boost::system::system_error*>(&exc);
|
||||||
errc && errc->code() == boost::asio::error::operation_aborted)
|
// errc && errc->code() == boost::asio::error::operation_aborted)
|
||||||
{
|
// {
|
||||||
co_return;
|
// co_return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
TOS::Logger("ServerSession").warn() << exc.what();
|
TOS::Logger("ServerSession").warn() << exc.what();
|
||||||
}
|
}
|
||||||
@@ -387,7 +388,7 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
|
|||||||
cube.Right.Z = co_await sock.read<uint8_t>();
|
cube.Right.Z = co_await sock.read<uint8_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto packet = std::make_unique<PP_Content_ChunkVoxels>(
|
PP_Content_ChunkVoxels *packet = new PP_Content_ChunkVoxels(
|
||||||
ToClient::L1::Content,
|
ToClient::L1::Content,
|
||||||
(uint8_t) ToClient::L2Content::ChunkVoxels,
|
(uint8_t) ToClient::L2Content::ChunkVoxels,
|
||||||
wcId,
|
wcId,
|
||||||
@@ -395,7 +396,7 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
|
|||||||
std::move(cubes)
|
std::move(cubes)
|
||||||
);
|
);
|
||||||
|
|
||||||
while(!NetInputPackets.push(std::move(packet)));
|
while(!NetInputPackets.push(packet));
|
||||||
|
|
||||||
LOG.info() << "Приняты воксели чанка " << int(wcId) << " / " << pos.X << ":" << pos.Y << ":" << pos.Z << " Вокселей " << cubes.size();
|
LOG.info() << "Приняты воксели чанка " << int(wcId) << " / " << pos.X << ":" << pos.Y << ":" << pos.Z << " Вокселей " << cubes.size();
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class ServerSession : public AsyncObject, public IServerSession, public ISurface
|
|||||||
glm::quat Quat;
|
glm::quat Quat;
|
||||||
} Camera;
|
} Camera;
|
||||||
|
|
||||||
boost::lockfree::spsc_queue<std::unique_ptr<ParsedPacket>> NetInputPackets;
|
boost::lockfree::spsc_queue<ParsedPacket*> NetInputPackets;
|
||||||
|
|
||||||
//
|
//
|
||||||
glm::vec3 PYR = glm::vec3(0), PYR_Offset = glm::vec3(0);
|
glm::vec3 PYR = glm::vec3(0), PYR_Offset = glm::vec3(0);
|
||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
void shutdown(EnumDisconnect type);
|
void shutdown(EnumDisconnect type);
|
||||||
|
|
||||||
bool isConnected() {
|
bool isConnected() {
|
||||||
return IsConnected;
|
return Socket->isAlive() && IsConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitShutdown() {
|
void waitShutdown() {
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ Vulkan::Vulkan(asio::io_context &ioc)
|
|||||||
getSettingsNext() = getBestSettings();
|
getSettingsNext() = getBestSettings();
|
||||||
reInit();
|
reInit();
|
||||||
|
|
||||||
addImGUIFont(LV::getResource("default.ttf")->makeView());
|
|
||||||
Game.ImGuiInterfaces.push_back(&Vulkan::gui_MainMenu);
|
Game.ImGuiInterfaces.push_back(&Vulkan::gui_MainMenu);
|
||||||
|
|
||||||
Game.MainThread = std::thread([&]() {
|
Game.MainThread = std::thread([&]() {
|
||||||
@@ -93,6 +92,7 @@ Vulkan::Vulkan(asio::io_context &ioc)
|
|||||||
Vulkan::~Vulkan()
|
Vulkan::~Vulkan()
|
||||||
{
|
{
|
||||||
Game.UseLock.wait_no_use();
|
Game.UseLock.wait_no_use();
|
||||||
|
Game.MainThread.join();
|
||||||
|
|
||||||
for(std::shared_ptr<IVulkanDependent> dependent : ROS_Dependents)
|
for(std::shared_ptr<IVulkanDependent> dependent : ROS_Dependents)
|
||||||
dependent->free(this);
|
dependent->free(this);
|
||||||
@@ -105,8 +105,6 @@ Vulkan::~Vulkan()
|
|||||||
glfwDestroyWindow(Graphics.Window);
|
glfwDestroyWindow(Graphics.Window);
|
||||||
Graphics.Window = nullptr;
|
Graphics.Window = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.MainThread.join();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vulkan::run()
|
void Vulkan::run()
|
||||||
@@ -122,9 +120,7 @@ void Vulkan::run()
|
|||||||
|
|
||||||
|
|
||||||
double prevTime = glfwGetTime();
|
double prevTime = glfwGetTime();
|
||||||
while(!NeedShutdown
|
while(!NeedShutdown)
|
||||||
|| (Game.Session && Game.Session->isConnected())
|
|
||||||
|| (Game.Server && Game.Server->GS.isAlive()))
|
|
||||||
{
|
{
|
||||||
float dTime = glfwGetTime()-prevTime;
|
float dTime = glfwGetTime()-prevTime;
|
||||||
prevTime = glfwGetTime();
|
prevTime = glfwGetTime();
|
||||||
@@ -142,13 +138,16 @@ void Vulkan::run()
|
|||||||
if(!NeedShutdown && glfwWindowShouldClose(Graphics.Window)) {
|
if(!NeedShutdown && glfwWindowShouldClose(Graphics.Window)) {
|
||||||
NeedShutdown = true;
|
NeedShutdown = true;
|
||||||
|
|
||||||
if(Game.Session) {
|
if(Game.Session)
|
||||||
Game.Session->shutdown(EnumDisconnect::ByInterface);
|
Game.Session->shutdown(EnumDisconnect::ByInterface);
|
||||||
}
|
|
||||||
|
|
||||||
if(Game.Server) {
|
if(Game.Server) {
|
||||||
Game.Server->GS.shutdown("Завершение работы из-за остановки клиента");
|
Game.Server->GS.shutdown("Завершение работы из-за остановки клиента");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Game.RSession = nullptr;
|
||||||
|
Game.Session = nullptr;
|
||||||
|
Game.Server = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Game.Session) {
|
if(Game.Session) {
|
||||||
@@ -428,12 +427,6 @@ void Vulkan::run()
|
|||||||
|
|
||||||
vkDestroySemaphore(Graphics.Device, SemaphoreImageAcquired, nullptr);
|
vkDestroySemaphore(Graphics.Device, SemaphoreImageAcquired, nullptr);
|
||||||
vkDestroySemaphore(Graphics.Device, SemaphoreDrawComplete, nullptr);
|
vkDestroySemaphore(Graphics.Device, SemaphoreDrawComplete, nullptr);
|
||||||
|
|
||||||
Graphics.ThisThread = std::thread::id();
|
|
||||||
|
|
||||||
Game.Session = nullptr;
|
|
||||||
Game.RSession = nullptr;
|
|
||||||
Game.Server = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vulkan::glfwCallbackError(int error, const char *description)
|
void Vulkan::glfwCallbackError(int error, const char *description)
|
||||||
@@ -1856,6 +1849,7 @@ void Vulkan::reInit()
|
|||||||
{
|
{
|
||||||
checkLibrary();
|
checkLibrary();
|
||||||
initNextSettings();
|
initNextSettings();
|
||||||
|
addImGUIFont(LV::getResource("default.ttf")->makeView());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vulkan::needFullVulkanRebuild()
|
bool Vulkan::needFullVulkanRebuild()
|
||||||
@@ -1899,12 +1893,15 @@ void Vulkan::addImGUIFont(std::string_view view) {
|
|||||||
fontConfig.OversampleV = 1;
|
fontConfig.OversampleV = 1;
|
||||||
|
|
||||||
auto &io = ImGui::GetIO();
|
auto &io = ImGui::GetIO();
|
||||||
uint8_t *fontPtr = new uint8_t[view.size()];
|
uint8_t *fontPtr = (uint8_t*) malloc(view.size());
|
||||||
|
if(!fontPtr)
|
||||||
|
MAKE_ERROR("Not enough memory");
|
||||||
|
|
||||||
std::copy(view.begin(), view.end(), fontPtr);
|
std::copy(view.begin(), view.end(), fontPtr);
|
||||||
try{
|
try{
|
||||||
io.Fonts->AddFontFromMemoryTTF(fontPtr, view.size(), 16.0f, &fontConfig, io.Fonts->GetGlyphRangesCyrillic());
|
io.Fonts->AddFontFromMemoryTTF(fontPtr, view.size(), 16.0f, &fontConfig, io.Fonts->GetGlyphRangesCyrillic());
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
delete[] fontPtr;
|
free(fontPtr);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#include "Net.hpp"
|
#include "Net.hpp"
|
||||||
#include <TOSLib.hpp>
|
#include <TOSLib.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
|
#include <boost/asio/error.hpp>
|
||||||
#include <boost/asio/socket_base.hpp>
|
#include <boost/asio/socket_base.hpp>
|
||||||
|
#include <boost/system/system_error.hpp>
|
||||||
|
|
||||||
namespace LV::Net {
|
namespace LV::Net {
|
||||||
|
|
||||||
@@ -116,7 +118,8 @@ std::string AsyncSocket::getError() const {
|
|||||||
|
|
||||||
bool AsyncSocket::isAlive() const {
|
bool AsyncSocket::isAlive() const {
|
||||||
return !SendPackets.Context->NeedShutdown
|
return !SendPackets.Context->NeedShutdown
|
||||||
&& !SendPackets.Context->RunSendShutdowned;
|
&& !SendPackets.Context->RunSendShutdowned
|
||||||
|
&& Socket.is_open();
|
||||||
}
|
}
|
||||||
|
|
||||||
coro<> AsyncSocket::read(std::byte *data, uint32_t size) {
|
coro<> AsyncSocket::read(std::byte *data, uint32_t size) {
|
||||||
@@ -138,7 +141,10 @@ coro<> AsyncSocket::read(std::byte *data, uint32_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AsyncSocket::closeRead() {
|
void AsyncSocket::closeRead() {
|
||||||
Socket.shutdown(boost::asio::socket_base::shutdown_receive);
|
if(Socket.is_open() && !ReadShutdowned) {
|
||||||
|
ReadShutdowned = true;
|
||||||
|
Socket.shutdown(boost::asio::socket_base::shutdown_receive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
coro<> AsyncSocket::waitForSend() {
|
coro<> AsyncSocket::waitForSend() {
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ protected:
|
|||||||
class AsyncSocket : public AsyncObject {
|
class AsyncSocket : public AsyncObject {
|
||||||
NetPool::Array<32> RecvBuffer, SendBuffer;
|
NetPool::Array<32> RecvBuffer, SendBuffer;
|
||||||
size_t RecvPos = 0, RecvSize = 0, SendSize = 0;
|
size_t RecvPos = 0, RecvSize = 0, SendSize = 0;
|
||||||
|
bool ReadShutdowned = false;
|
||||||
tcp::socket Socket;
|
tcp::socket Socket;
|
||||||
|
|
||||||
static constexpr uint32_t
|
static constexpr uint32_t
|
||||||
|
|||||||
57
Src/main.cpp
57
Src/main.cpp
@@ -1,74 +1,19 @@
|
|||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <boost/asio/buffer.hpp>
|
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
|
||||||
#include <boost/asio/detached.hpp>
|
|
||||||
#include <boost/asio/detail/chrono.hpp>
|
|
||||||
#include <boost/asio/io_context.hpp>
|
|
||||||
#include <boost/asio/write.hpp>
|
|
||||||
#include <boost/chrono/duration.hpp>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <boost/asio.hpp>
|
||||||
#include "Client/ServerSession.hpp"
|
|
||||||
#include "Common/Net.hpp"
|
|
||||||
#include "Common/Packets.hpp"
|
|
||||||
#include "Server/GameServer.hpp"
|
|
||||||
#include <Client/Vulkan/Vulkan.hpp>
|
#include <Client/Vulkan/Vulkan.hpp>
|
||||||
|
|
||||||
namespace LV {
|
namespace LV {
|
||||||
|
|
||||||
using namespace TOS;
|
using namespace TOS;
|
||||||
|
|
||||||
std::unique_ptr<Client::ServerSession> session;
|
|
||||||
|
|
||||||
coro<> runClient(asio::io_context &ioc, uint16_t port) {
|
|
||||||
try {
|
|
||||||
tcp::socket sock = co_await Net::asyncConnectTo("localhost:"+std::to_string(port));
|
|
||||||
co_await Client::ServerSession::asyncAuthorizeWithServer(sock, "DrSocalkwe3n", "1password2", 1);
|
|
||||||
std::unique_ptr<Net::AsyncSocket> asock = co_await Client::ServerSession::asyncInitGameProtocol(ioc, std::move(sock));
|
|
||||||
session = std::make_unique<Client::ServerSession>(ioc, std::move(asock), nullptr);
|
|
||||||
} catch(const std::exception &exc) {
|
|
||||||
std::cout << exc.what() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
// LuaVox
|
// LuaVox
|
||||||
|
|
||||||
asio::io_context ioc;
|
asio::io_context ioc;
|
||||||
|
|
||||||
LV::Client::VK::Vulkan vkInst(ioc);
|
LV::Client::VK::Vulkan vkInst(ioc);
|
||||||
ioc.run();
|
ioc.run();
|
||||||
|
|
||||||
// Server::GameServer gs(ioc, "");
|
|
||||||
|
|
||||||
// Net::Server server(ioc, [&](tcp::socket sock) -> coro<> {
|
|
||||||
// server.stop();
|
|
||||||
// co_await gs.pushSocketConnect(std::move(sock));
|
|
||||||
// }, 6666);
|
|
||||||
|
|
||||||
// std::cout << server.getPort() << std::endl;
|
|
||||||
|
|
||||||
// asio::co_spawn(ioc, runClient(ioc, server.getPort()), asio::detached);
|
|
||||||
|
|
||||||
|
|
||||||
// auto ot = std::async([&](){
|
|
||||||
// VkInst.start([&](VK::Vulkan *instance, int subpass, VkCommandBuffer &renderCmd)
|
|
||||||
// {
|
|
||||||
// if(glfwWindowShouldClose(VkInst.Graphics.Window) || (session && !session->isConnected())) {
|
|
||||||
// VkInst.shutdown();
|
|
||||||
|
|
||||||
// if(glfwWindowShouldClose(VkInst.Graphics.Window) && session)
|
|
||||||
// session->shutdown(EnumDisconnect::ByInterface);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// session = nullptr;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// ioc.run();
|
|
||||||
// VkInst.shutdown();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user