#ifndef STAR_SYSTEM_WORLD_SERVER_THREAD_HPP #define STAR_SYSTEM_WORLD_SERVER_THREAD_HPP #include "StarSystemWorldServer.hpp" #include "StarThread.hpp" #include "StarNetPackets.hpp" namespace Star { STAR_CLASS(SystemWorldServerThread); typedef function ClientShipAction; class SystemWorldServerThread : public Thread { public: SystemWorldServerThread(Vec3I const& location, SystemWorldServerPtr systemWorld, String storageFile); ~SystemWorldServerThread(); Vec3I location() const; List clients(); void addClient(ConnectionId clientId, Uuid const& uuid, float shipSpeed, SystemLocation const& location); void removeClient(ConnectionId clientId); void setPause(shared_ptr> pause); void run() override; void stop(); void update(); void setClientDestination(ConnectionId clientId, SystemLocation const& location); void executeClientShipAction(ConnectionId clientId, ClientShipAction action); SystemLocation clientShipLocation(ConnectionId clientId); Maybe> clientWarpAction(ConnectionId clientId); SkyParameters clientSkyParameters(ConnectionId clientId); List activeInstanceWorlds() const; // callback to be run after update in the server thread void setUpdateAction(function updateAction); void pushIncomingPacket(ConnectionId clientId, PacketPtr packet); List pullOutgoingPackets(ConnectionId clientId); void store(); private: Vec3I m_systemLocation; SystemWorldServerPtr m_systemWorld; atomic m_stop{false}; float m_periodicStorage{300.0f}; bool m_triggerStorage{ false}; String m_storageFile; shared_ptr> m_pause; function m_updateAction; ReadersWriterMutex m_mutex; ReadersWriterMutex m_queueMutex; HashSet m_clients; HashMap m_clientShipDestinations; HashMap> m_clientShipLocations; HashMap> m_clientWarpActions; List> m_clientShipActions; List m_activeInstanceWorlds; Map> m_outgoingPacketQueue; List> m_incomingPacketQueue; }; } #endif