-
Notifications
You must be signed in to change notification settings - Fork 5
/
fightnetplay.cpp
65 lines (50 loc) · 1.78 KB
/
fightnetplay.cpp
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
#include "fightnetplay.h"
#include <assert.h>
#include <prism/netplay.h>
#include "gamelogic.h"
#include "playerdefinition.h"
#include "mugencommandhandler.h"
#include "netplaylogic.h"
static struct {
bool mHasReceivedNetplayData;
FightNetplayData mCachedReceivedNetplayData;
} gFightNetplayData;
static void fightNetplayReceiveCB(void* tCaller, const Buffer& tData);
struct FightSyncCheckData {
int mLife1;
int mLife2;
};
static Buffer gatherNetplaySyncCheckData(void*) {
Buffer b = makeBufferEmptyOwned();
FightSyncCheckData syncCheckData;
syncCheckData.mLife1 = getPlayerLife(getRootPlayer(0));
syncCheckData.mLife2 = getPlayerLife(getRootPlayer(1));
appendBufferBuffer(&b, makeBuffer(&syncCheckData, sizeof(FightSyncCheckData)));
return b;
}
static int checkNetplaySyncCheckData(void*, const Buffer& b1, const Buffer& b2) {
const auto checkData1 = (FightSyncCheckData*)b1.mData;
const auto checkData2 = (FightSyncCheckData*)b2.mData;
return checkData1->mLife1 == checkData2->mLife1 && checkData1->mLife2 == checkData2->mLife2;
}
static void initFightNetplay(void*) {
gFightNetplayData.mHasReceivedNetplayData = false;
setNetplaySyncCBs(gatherNetplaySyncCheckData, NULL, checkNetplaySyncCheckData, NULL);
}
static void shutdownFightNetplay(void*) {
setNetplaySyncCBs(NULL, NULL, NULL, NULL);
}
int hasNewFightNetplayReceivedData() {
return gFightNetplayData.mHasReceivedNetplayData;
}
FightNetplayData popFightNetplayReceivedData() {
assert(gFightNetplayData.mHasReceivedNetplayData);
gFightNetplayData.mHasReceivedNetplayData = false;
return gFightNetplayData.mCachedReceivedNetplayData;
}
void sendFightNetplayData(const Buffer& tData) {
sendNetplayData(tData);
}
ActorBlueprint getFightNetplayBlueprint() {
return makeActorBlueprint(initFightNetplay, shutdownFightNetplay);
}