no src
This commit is contained in:
73
modules/ClientModule/ClientModule.h
Normal file
73
modules/ClientModule/ClientModule.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
#include "utils/Events/NetworkEvents.h"
|
||||
|
||||
class ClientModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
ClientModule(Archimedes::App*, void*);
|
||||
|
||||
ClientModule() { name = "ClientModule"; }
|
||||
|
||||
~ClientModule();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
|
||||
void startClient(SteamNetworkingIPAddr&);
|
||||
void stopClient();
|
||||
|
||||
void sendReliable(const void* data, uint32 byteCount) {
|
||||
interface->SendMessageToConnection(connection, data, byteCount, k_nSteamNetworkingSend_Reliable, nullptr);
|
||||
app->emitEvent(new Archimedes::DataSentEvent(data, byteCount));
|
||||
}
|
||||
|
||||
bool isRunning() const { return running; }
|
||||
|
||||
bool isConnected() const { return connection != k_HSteamNetConnection_Invalid; }
|
||||
|
||||
void pollIncomingData();
|
||||
|
||||
void shouldHandleEvents(unsigned int events) { eventsToHandle = events; }
|
||||
|
||||
enum CMEventEnum {
|
||||
None = 0,
|
||||
ConnectionStatusChanged = 1 << 0,
|
||||
DataRecieved = 1 << 1,
|
||||
DataSent = 1 << 2
|
||||
};
|
||||
private:
|
||||
|
||||
unsigned int eventsToHandle = CMEventEnum::ConnectionStatusChanged | CMEventEnum::DataSent | CMEventEnum::DataRecieved;
|
||||
|
||||
bool running = false;
|
||||
|
||||
ISteamNetworkingSockets* interface;
|
||||
HSteamNetConnection connection;
|
||||
|
||||
inline static ClientModule* callbackInstance = nullptr;
|
||||
|
||||
static void SteamNetConnectionStatusChangedCallback( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
callbackInstance->OnSteamNetConnectionStatusChanged( pInfo );
|
||||
}
|
||||
|
||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
|
||||
}
|
||||
|
||||
void PollConnectionStateChanges() {
|
||||
callbackInstance = this;
|
||||
interface->RunCallbacks();
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef CLIENTMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ClientModule
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
Reference in New Issue
Block a user