mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
Introduce RunMode enum and thread pool sizing helpers for client, server, and hybrid modes. Add compute pool to server world and pass mode through server/client initialization.
35 lines
846 B
C++
35 lines
846 B
C++
#pragma once
|
|
#include "Cubed/config.hpp"
|
|
#include "Cubed/gameplay/server_world.hpp"
|
|
#include "Cubed/gameplay/session.hpp"
|
|
|
|
#include <asio.hpp>
|
|
#include <thread>
|
|
namespace Cubed {
|
|
|
|
class NetworkServer {
|
|
public:
|
|
explicit NetworkServer();
|
|
~NetworkServer();
|
|
void stop();
|
|
|
|
// Run in another thread after initialization is complete
|
|
void start_server(int port, RunMode mode);
|
|
int port() const;
|
|
ServerWorld& server_world();
|
|
|
|
private:
|
|
Config m_config;
|
|
|
|
asio::io_context m_io;
|
|
std::thread m_net_thread;
|
|
int m_port = 25530;
|
|
std::atomic<bool> m_stopped{false};
|
|
std::atomic<bool> m_started{false};
|
|
ServerWorld m_world;
|
|
std::mutex m_session_mutex;
|
|
std::unordered_map<std::string, std::shared_ptr<Session>> m_session;
|
|
asio::awaitable<void> listen();
|
|
void net_run();
|
|
};
|
|
} // namespace Cubed
|