|
This thread is locked; no one can reply to it. |
1
2
|
Object Serialization C++ |
ImLeftFooted
Member #3,935
October 2003
|
I was favoring familiar language over accuracy. AMCerasoli said: And what happened with the port of your game to the iPhone? To be honest I've totally forgotten. Which game are you referring to? |
AMCerasoli
Member #11,955
May 2010
|
Hahaha man what did you smoke?... You even posted some images... Here...
|
ImLeftFooted
Member #3,935
October 2003
|
Oh yeah, that was fun. Maybe I'll dedicate a weekend to it one of these weeks... |
AMCerasoli
Member #11,955
May 2010
|
Well, here it's another example if someone is interested. 1class OPC_DATA{
2
3 public:
4
5 bool modalidad_normal;
6 bool catg0, catg1, catg2, catg3, catg4;
7 ALLEGRO_USTR* URL_page;
8 float sfx, music;
9 bool fullscreen;
10 int len;
11
12
13 OPC_DATA() {
14
15 ALLEGRO_FILE* file = al_fopen("Datos/datos.dat", "rb");
16
17 if(file){ ///If file exist...
18
19 modalidad_normal = al_fread32be(file);
20 catg0 = al_fread32be(file);
21 catg1 = al_fread32be(file);
22 catg2 = al_fread32be(file);
23 catg3 = al_fread32be(file);
24 catg4 = al_fread32be(file);
25 len = al_fread32be(file);
26
27 char *buf = new char [len];
28 al_fread(file, buf, len);
29 URL_page = al_ustr_new(buf);
30
31 int T_sfx = al_fread32be(file);
32 sfx = *reinterpret_cast<float*>(&T_sfx);
33
34 int T_music = al_fread32be(file);
35 music = *reinterpret_cast<float*>(&T_music);
36
37 fullscreen = al_fread32be(file);
38
39 al_fclose(file);
40 Beep(800,200);
41
42 }else{ /// If file doesn't exist...
43
44 modalidad_normal = true;
45 catg0 = true;
46 catg1 = true;
47 catg2 = true;
48 catg3 = true;
49 catg4 = true;
50 URL_page = al_ustr_new("www.Somestring.com");
51 sfx = 1.6;
52 music = 1.5;
53 fullscreen = false;
54
55 al_fclose(file);
56 }
57
58 }
59
60 ~OPC_DATA() {
61
62 ALLEGRO_FILE* file = al_fopen("Datos/datos.dat", "wb");
63
64 al_fwrite32be(file, modalidad_normal);
65 al_fwrite32be(file, catg0);
66 al_fwrite32be(file, catg1);
67 al_fwrite32be(file, catg2);
68 al_fwrite32be(file, catg3);
69 al_fwrite32be(file, catg4);
70
71 al_fwrite32be(file, (int)al_ustr_size(URL_page));
72 al_fwrite(file, al_cstr(URL_page), al_ustr_size(URL_page));
73
74 al_fwrite32be(file, *reinterpret_cast<int*>(&sfx));
75 al_fwrite32be(file, *reinterpret_cast<int*>(&music));
76 al_fwrite32be(file, fullscreen);
77
78 al_fclose(file);
79
80 }
81
82};
I had to use 32 bits to save booleans because it seems that even when their size it's just one bit al_fputc didn't work.
|
|
1
2
|