Polyphase Game Engine
Loading...
Searching...
No Matches
ControllerServer.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
6
7#include <atomic>
8#include <functional>
9#include <future>
10#include <memory>
11#include <mutex>
12#include <queue>
13#include <string>
14
15// Forward-declared PIMPL — hides crow::SimpleApp from the header to avoid WinSock conflicts
16struct ControllerServerImpl;
17
18class ControllerServer
19{
20public:
21 static void Create();
22 static void Destroy();
23 static ControllerServer* Get();
24
25 void Start(int port);
26 void Stop();
27 void Restart(int port);
28 bool IsRunning() const;
29 bool IsShuttingDown() const { return mShuttingDown.load(); }
30
31 void Tick();
32
33 std::future<std::string> QueueCommand(std::function<std::string()> fn);
34
35 void SetLogRequests(bool log);
36 bool GetLogRequests() const;
37
38private:
39 ControllerServer();
40 ~ControllerServer();
41
42 void DrainAndCancelQueue();
43
44 static ControllerServer* sInstance;
45
46 std::unique_ptr<ControllerServerImpl> mImpl;
47 std::future<void> mServerFuture;
48 std::atomic<bool> mRunning{ false };
49 std::atomic<bool> mShuttingDown{ false };
50 std::atomic<bool> mLogRequests{ false };
51 int mPort = 7890;
52
53 std::mutex mQueueMutex;
54 std::queue<std::unique_ptr<ControllerCommand>> mCommandQueue;
55};
56
57#endif
bool IsShuttingDown()
Definition Engine.cpp:1042
void Tick()
Definition HttpClient.cpp:202