forked from Ramblurr/scriptbots
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Base.cpp
52 lines (39 loc) · 1010 Bytes
/
Base.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
#include "Base.h"
// For getting file size:
#include <sys/types.h> // remove
#include <sys/stat.h>
#include <unistd.h> //remove
using namespace std;
Base::Base()
{
world = new World();
}
void Base::saveWorld()
{
// save data to archive -----------------------------
ofstream ofs("myworld.dat"); // create and open a character archive for output
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << (*world);
// archive and stream closed when destructors are called
// Get file size:
struct stat filestatus;
stat( "myworld.dat", &filestatus);
cout << endl << endl << "World Saved: " << filestatus.st_size/1048576 << " MB" << endl;
cout << endl;
//world->printState();
}
void Base::loadWorld()
{
cout << endl << "LOADING FILE" << endl;
ifstream ifs("myworld.dat");
if( !ifs )
{
cout << "Error: File does not exist." << endl << endl;
exit(0);
}
boost::archive::text_iarchive ia(ifs);
ia >> (*world);
cout << endl;
world->printState();
}