Cube  Diff

Differences From Artifact [7c09343b90]:

To Artifact [b5a43a0cf0]:


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	if (demorecording)
		stop();
}

void
savestate(OFIRI *IRI)
{
	@autoreleasepool {
		stop();
		f = gzopen([IRI.fileSystemRepresentation
		               cStringWithEncoding:OFLocale.encoding],
		    "wb9");
		if (!f) {
			conoutf(@"could not write %@", IRI.string);
			return;
		}
		gzwrite(f, (void *)"CUBESAVE", 8);
		gzputc(f, islittleendian);
		gzputi(SAVEGAMEVERSION);
		OFData *data = [player1 dataBySerializing];
		gzputi(data.count);
		char map[_MAXDEFSTR] = { 0 };
		memcpy(map, getclientmap().UTF8String,
		    min(getclientmap().UTF8StringLength, _MAXDEFSTR - 1));
		gzwrite(f, map, _MAXDEFSTR);
		gzputi(gamemode);
		gzputi(ents.length());
		loopv(ents) gzputc(f, ents[i].spawned);
		gzwrite(f, data.items, data.count);
		OFArray<DynamicEntity *> *monsters = getmonsters();
		gzputi(monsters.count);
		for (DynamicEntity *monster in monsters) {
			data = [monster dataBySerializing];
			gzwrite(f, data.items, data.count);
		}
		gzputi(players.count);
		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;
	}

	@autoreleasepool {
		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)
{
	@autoreleasepool {
		stop();
		if (multiplayer())
			return;
		f = gzopen([IRI.fileSystemRepresentation
		               cStringWithEncoding:OFLocale.encoding],
		    "rb9");
		if (!f) {
			conoutf(@"could not open %@", IRI.string);
			return;
		}

		char mapname[_MAXDEFSTR] = { 0 };
		char buf[8];
		gzread(f, buf, 8);
		if (strncmp(buf, "CUBESAVE", 8))
			goto out;
		if (gzgetc(f) != islittleendian)
			goto out; // not supporting save->load accross
			          // incompatible architectures simpifies things
			          // a LOT
		if (gzgeti() != SAVEGAMEVERSION ||
		    gzgeti() != DynamicEntity.serializedSize)
			goto out;
		gzread(f, mapname, _MAXDEFSTR);
		nextmode = gzgeti();
		@autoreleasepool {
			// continue below once map has been loaded and client &
			// server have updated
			changemap(@(mapname));
		}
		return;
	out:
		conoutf(@"aborting: savegame/demo from a different version of "
		        @"cube or cpu architecture");
		stop();
	}
}

void
loadgame(OFString *name)
{
	@autoreleasepool {
		OFString *path =
		    [OFString stringWithFormat:@"savegames/%@.csgz", name];
		OFIRI *IRI = [Cube.sharedInstance.userDataIRI
		    IRIByAppendingPathComponent:path];
		loadstate(IRI);
	}
}
COMMAND(loadgame, ARG_1STR)

void
loadgameout()
{
	stop();







<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<











<
<
|
|
|
|
|
|
<






<
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
<
|
|
|
|
|
<





<
<
|
|
|
|
<







87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175
176

177
178
179
180
181

182
183
184
185
186


187
188
189
190

191
192
193
194
195
196
197
	if (demorecording)
		stop();
}

void
savestate(OFIRI *IRI)
{

	stop();
	f = gzopen([IRI.fileSystemRepresentation
	               cStringWithEncoding:OFLocale.encoding],
	    "wb9");
	if (!f) {
		conoutf(@"could not write %@", IRI.string);
		return;
	}
	gzwrite(f, (void *)"CUBESAVE", 8);
	gzputc(f, islittleendian);
	gzputi(SAVEGAMEVERSION);
	OFData *data = [player1 dataBySerializing];
	gzputi(data.count);
	char map[_MAXDEFSTR] = { 0 };
	memcpy(map, getclientmap().UTF8String,
	    min(getclientmap().UTF8StringLength, _MAXDEFSTR - 1));
	gzwrite(f, map, _MAXDEFSTR);
	gzputi(gamemode);
	gzputi(ents.length());
	loopv(ents) gzputc(f, ents[i].spawned);
	gzwrite(f, data.items, data.count);
	OFArray<DynamicEntity *> *monsters = getmonsters();
	gzputi(monsters.count);
	for (DynamicEntity *monster in monsters) {
		data = [monster dataBySerializing];
		gzwrite(f, data.items, data.count);
	}
	gzputi(players.count);
	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;
	f = gzopen([IRI.fileSystemRepresentation
	               cStringWithEncoding:OFLocale.encoding],
	    "rb9");
	if (!f) {
		conoutf(@"could not open %@", IRI.string);
		return;
	}

	char mapname[_MAXDEFSTR] = { 0 };
	char buf[8];
	gzread(f, buf, 8);
	if (strncmp(buf, "CUBESAVE", 8))
		goto out;
	if (gzgetc(f) != islittleendian)
		goto out; // not supporting save->load accross
		          // incompatible architectures simpifies things
		          // a LOT
	if (gzgeti() != SAVEGAMEVERSION ||
	    gzgeti() != DynamicEntity.serializedSize)
		goto out;
	gzread(f, mapname, _MAXDEFSTR);
	nextmode = gzgeti();

	// continue below once map has been loaded and client & server
	// have updated
	changemap(@(mapname));

	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();
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
		return;
	}

	int cn = getclientnum();
	if (cn < 0)
		return;

	@autoreleasepool {
		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;







<
<
|
|
|
|
|
|
|
|
|
<







270
271
272
273
274
275
276


277
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
		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;
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
		// the network
	}
}

void
demo(OFString *name)
{
	@autoreleasepool {
		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);







<
<
|
|
|
|
|
<







329
330
331
332
333
334
335


336
337
338
339
340

341
342
343
344
345
346
347
		// 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);