TDME2  1.9.200
ApplicationServer.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 
6 #include <tdme/tdme.h>
13 #include <tdme/utilities/Console.h>
14 
15 using std::make_unique;
16 using std::string;
17 using std::to_string;
18 using std::unique_ptr;
19 
21 
28 
29 ApplicationServer::ApplicationServer(const string& name, const string& host, const uint16_t port, const unsigned int maxCCU, int pathFindingThreadCount) : UDPServer(name, host, port, maxCCU), pathFindingThreadCount(pathFindingThreadCount) {
32 
33  //
34  Console::println("ApplicationServer::ApplicationServer(): Starting WS UDP server @ " + host + ":" + to_string(port));
35 }
36 
38  Console::println("ApplicationServer::createContext()");
39  return new Context(true);
40 }
41 
43  // init
44  Console::println("ApplicationServer::ApplicationServer(): Initializing");
45 
46  //
47  context = unique_ptr<Context>(createContext());
48  context->getPathFinding()->setThreadCount(pathFindingThreadCount);
49  context->setWorld(new World("applicationserver-world"));
50  // set up logics
51  setupLogics();
52  //
53  context->addNewLogics();
54  logicsThread = make_unique<ServerThread>(context.get(), this);
55  context->setLogicsMutex(this->logicsThread->getMutex());
56 
57  // starting game logic thread
58  Console::println("ApplicationServer::ApplicationServer(): Starting game logic thread");
59  logicsThread->start();
60 
61  //
62  UDPServer::start();
63 }
64 
66  Console::println("ApplicationServer::~ApplicationServer(): Shutting down");
67 
68  //
69  logicsThread->stop();
70  logicsThread->join();
71 
72  //
73  context->shutdown();
74 }
75 
76 UDPServerClient* ApplicationServer::accept(const uint32_t clientId, const std::string& ip, const uint16_t port) {
77  Console::println("Accepting client connection with '" + ip + ":" + to_string(port) + "'");
78 
79  //
80  return new ApplicationServerClient(clientId, ip, port);
81 }
virtual UDPServerClient * accept(const uint32_t clientId, const string &ip, const uint16_t port) override
Accept.
virtual void start() override
Starts this objects thread.
unique_ptr< ServerThread > logicsThread
virtual void setupLogics()=0
Setup default / minumum required logics.
virtual Context * createContext()
Create context.
Application server thread.
Definition: ServerThread.h:25
Dynamic physics world class.
Definition: World.h:38
void setIOThreadCount(int ioThreadCount)
Sets up the numbers of threads to handle IO and framing.
Definition: Server.h:64
void setWorkerThreadCount(int workerThreadCount)
Sets up the number of workers that handle requests in thread pool.
Definition: Server.h:72
Base class for network UDP server clients.
Base class for network UDP servers.
Definition: UDPServer.h:42
Console class.
Definition: Console.h:29