-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDemo.cpp
45 lines (44 loc) · 974 Bytes
/
Demo.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
#include "Demo.h"
#include "FileIO.h"
void SaveDemo(demoSystem dem)
{
CFileIO fIO;
fIO.GetFile("Data/Demo1.dem","wb");
fIO.WriteBinary(&dem.iScrollOffset,1);
int bufsize = (int)dem.mKeyBuffer.size();
fIO.WriteBinary(&bufsize,1);
if(bufsize>0)
{
list<keyBuffer>::iterator i;
for(i = dem.mKeyBuffer.begin(); i != dem.mKeyBuffer.end(); i++)
{
fIO.WriteBinary(&(*i).tick,1);
fIO.WriteBinary(&(*i).KeyStateChange,1);
fIO.WriteBinary(&(*i).KeyStates,1);
}
}
}
bool LoadDemo(demoSystem& dem, int demo)
{
char name[256];
sprintf(name,"Data/Demo%i.dem",demo);
dem.mKeyBuffer.clear();
CFileIO fIO;
if(!fIO.GetFile(name,"rb"))
return false;
fIO.ReadBinary(&dem.iScrollOffset,1);
int bufsize,n;
fIO.ReadBinary(&bufsize,1);
if(bufsize>0)
{
for(n=0;n<bufsize;n++)
{
keyBuffer kb;
fIO.ReadBinary(&kb.tick,1);
fIO.ReadBinary(&kb.KeyStateChange,1);
fIO.ReadBinary(&kb.KeyStates,1);
dem.mKeyBuffer.push_back(kb);
}
}
return true;
}