-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameSessionViewModel.cpp
More file actions
102 lines (74 loc) · 2.1 KB
/
GameSessionViewModel.cpp
File metadata and controls
102 lines (74 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "GameSessionViewModel.h"
#include "stormancer/IClientFactory.h"
#include "gamesession/GameSession.hpp"
#include "Lockstep.h"
#include "ViewModel.h"
GameSessionViewModel::GameSessionViewModel(ClientViewModel* parent)
:parent(parent)
, lockstep(new LockstepViewModel(this))
{
}
void GameSessionViewModel::initialize()
{
lockstep->initialize();
}
bool GameSessionViewModel::isInGameSession()
{
auto client = Stormancer::IClientFactory::GetClient(this->parent->id);
auto gameSession = client->dependencyResolver().resolve<Stormancer::GameSessions::GameSession>();
return gameSession->isInSession();
}
void GameSessionViewModel::setPlayerReady()
{
auto client = Stormancer::IClientFactory::GetClient(this->parent->id);
auto gameSession = client->dependencyResolver().resolve<Stormancer::GameSessions::GameSession>();
this->parent->isProcessing = true;
gameSession->setPlayerReady().then([this](pplx::task<void> t)
{
this->parent->isProcessing = false;
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
void GameSessionViewModel::leaveGameSession()
{
auto client = Stormancer::IClientFactory::GetClient(this->parent->id);
auto gameSession = client->dependencyResolver().resolve<Stormancer::GameSessions::GameSession>();
this->parent->isProcessing = true;
gameSession->disconnectFromGameSession().then([this](pplx::task<void> t)
{
this->parent->isProcessing = false;
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
std::vector<P2PRemotePeerViewModel> GameSessionViewModel::getP2PRemotePeers()
{
auto client = Stormancer::IClientFactory::GetClient(this->parent->id);
auto gameSession = client->dependencyResolver().resolve<Stormancer::GameSessions::GameSession>();
std::vector<P2PRemotePeerViewModel> results;
if (gameSession->scene())
{
auto peers = gameSession->scene()->connectedPeers();
for (auto p : peers)
{
P2PRemotePeerViewModel vm;
vm.isRelay = p->useRelay();
vm.sessionId = p->sessionId().toString();
results.push_back(vm);
}
}
return results;
}