1
2
3
4
5
6
7
8
9
10
11
12
|
// loading and saving of savegames & demos, dumps the spawn state of all
// mapents, the full state of all dynents (monsters + player)
#include "cube.h"
#import "DynamicEntity.h"
#import "Entity.h"
#import "Monster.h"
#ifdef OF_BIG_ENDIAN
static const int islittleendian = 0;
#else
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// loading and saving of savegames & demos, dumps the spawn state of all
// mapents, the full state of all dynents (monsters + player)
#include "cube.h"
#import "Command.h"
#import "DynamicEntity.h"
#import "Entity.h"
#import "Monster.h"
#ifdef OF_BIG_ENDIAN
static const int islittleendian = 0;
#else
|
︙ | | | ︙ | |
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
for (id player in players) {
gzput(player == [OFNull null]);
data = [player dataBySerializing];
gzwrite(f, data.items, data.count);
}
}
void
savegame(OFString *name)
{
if (!m_classicsp) {
conoutf(@"can only save classic sp games");
return;
}
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
savestate(IRI);
stop();
conoutf(@"wrote %@", IRI.string);
}
COMMAND(savegame, ARG_1STR)
void
loadstate(OFIRI *IRI)
{
stop();
if (multiplayer())
return;
|
<
|
<
|
<
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
for (id player in players) {
gzput(player == [OFNull null]);
data = [player dataBySerializing];
gzwrite(f, data.items, data.count);
}
}
COMMAND(savegame, ARG_1STR, (^(OFString *name) {
if (!m_classicsp) {
conoutf(@"can only save classic sp games");
return;
}
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
savestate(IRI);
stop();
conoutf(@"wrote %@", IRI.string);
}))
void
loadstate(OFIRI *IRI)
{
stop();
if (multiplayer())
return;
|
︙ | | | ︙ | |
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
return;
out:
conoutf(@"aborting: savegame/demo from a different version of "
@"cube or cpu architecture");
stop();
}
void
loadgame(OFString *name)
{
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
loadstate(IRI);
}
COMMAND(loadgame, ARG_1STR)
void
loadgameout()
{
stop();
conoutf(@"loadgame incomplete: savegame from a different version of "
@"this map");
|
<
|
<
|
<
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
return;
out:
conoutf(@"aborting: savegame/demo from a different version of "
@"cube or cpu architecture");
stop();
}
COMMAND(loadgame, ARG_1STR, (^(OFString *name) {
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
loadstate(IRI);
}))
void
loadgameout()
{
stop();
conoutf(@"loadgame incomplete: savegame from a different version of "
@"this map");
|
︙ | | | ︙ | |
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
// demo functions
int starttime = 0;
int playbacktime = 0;
int ddamage, bdamage;
OFVector3D dorig;
void
record(OFString *name)
{
if (m_sp) {
conoutf(@"cannot record singleplayer games");
return;
}
int cn = getclientnum();
if (cn < 0)
return;
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
savestate(IRI);
gzputi(cn);
conoutf(@"started recording demo to %@", IRI.string);
demorecording = true;
starttime = lastmillis;
ddamage = bdamage = 0;
}
COMMAND(record, ARG_1STR)
void
demodamage(int damage, const OFVector3D *o)
{
ddamage = damage;
dorig = *o;
}
|
<
|
<
|
<
|
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
// demo functions
int starttime = 0;
int playbacktime = 0;
int ddamage, bdamage;
OFVector3D dorig;
COMMAND(record, ARG_1STR, (^(OFString *name) {
if (m_sp) {
conoutf(@"cannot record singleplayer games");
return;
}
int cn = getclientnum();
if (cn < 0)
return;
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
savestate(IRI);
gzputi(cn);
conoutf(@"started recording demo to %@", IRI.string);
demorecording = true;
starttime = lastmillis;
ddamage = bdamage = 0;
}))
void
demodamage(int damage, const OFVector3D *o)
{
ddamage = damage;
dorig = *o;
}
|
︙ | | | ︙ | |
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
ddamage = 0;
}
// FIXME: add all other client state which is not send through
// the network
}
}
void
demo(OFString *name)
{
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
loadstate(IRI);
demoloading = true;
}
COMMAND(demo, ARG_1STR)
void
stopreset()
{
conoutf(@"demo stopped (%d msec elapsed)", lastmillis - starttime);
stop();
[players removeAllObjects];
|
<
|
<
|
<
|
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
ddamage = 0;
}
// FIXME: add all other client state which is not send through
// the network
}
}
COMMAND(demo, ARG_1STR, (^(OFString *name) {
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
loadstate(IRI);
demoloading = true;
}))
void
stopreset()
{
conoutf(@"demo stopped (%d msec elapsed)", lastmillis - starttime);
stop();
[players removeAllObjects];
|
︙ | | | ︙ | |
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
}
break;
}
}
// if(player1->state!=CS_DEAD) showscores(false);
}
void
stopn()
{
if (demoplayback)
stopreset();
else
stop();
conoutf(@"demo stopped");
}
COMMANDN(stop, stopn, ARG_NONE)
|
<
|
<
|
<
|
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
}
break;
}
}
// if(player1->state!=CS_DEAD) showscores(false);
}
COMMAND(stop, ARG_NONE, ^{
if (demoplayback)
stopreset();
else
stop();
conoutf(@"demo stopped");
})
|