220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
restoreserverstate(ents);
OFMutableData *data =
[OFMutableData dataWithCapacity:DynamicEntity.serializedSize];
[data increaseCountBy:DynamicEntity.serializedSize];
gzread(f, data.mutableItems, data.count);
[player1 setFromSerializedData:data];
player1.lastaction = lastmillis;
int nmonsters = gzgeti();
OFArray<DynamicEntity *> *monsters = getmonsters();
if (nmonsters != monsters.count)
return loadgameout();
for (DynamicEntity *monster in monsters) {
gzread(f, data.mutableItems, data.count);
[monster setFromSerializedData:data];
// lazy, could save id of enemy instead
monster.enemy = player1;
// also lazy, but no real noticable effect on game
monster.lastaction = monster.trigger = lastmillis + 500;
if (monster.state == CS_DEAD)
monster.lastaction = 0;
}
restoremonsterstate();
int nplayers = gzgeti();
loopi(nplayers) if (!gzget())
{
DynamicEntity *d = getclient(i);
|
|
|
|
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
restoreserverstate(ents);
OFMutableData *data =
[OFMutableData dataWithCapacity:DynamicEntity.serializedSize];
[data increaseCountBy:DynamicEntity.serializedSize];
gzread(f, data.mutableItems, data.count);
[player1 setFromSerializedData:data];
player1.lastAction = lastmillis;
int nmonsters = gzgeti();
OFArray<DynamicEntity *> *monsters = getmonsters();
if (nmonsters != monsters.count)
return loadgameout();
for (DynamicEntity *monster in monsters) {
gzread(f, data.mutableItems, data.count);
[monster setFromSerializedData:data];
// lazy, could save id of enemy instead
monster.enemy = player1;
// also lazy, but no real noticable effect on game
monster.lastAction = monster.trigger = lastmillis + 500;
if (monster.state == CS_DEAD)
monster.lastAction = 0;
}
restoremonsterstate();
int nplayers = gzgeti();
loopi(nplayers) if (!gzget())
{
DynamicEntity *d = getclient(i);
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
if (!demorecording)
return;
gzputi(lastmillis - starttime);
gzputi(len);
gzwrite(f, buf, len);
gzput(extras);
if (extras) {
gzput(player1.gunselect);
gzput(player1.lastattackgun);
gzputi(player1.lastaction - starttime);
gzputi(player1.gunwait);
gzputi(player1.health);
gzputi(player1.armour);
gzput(player1.armourtype);
loopi(NUMGUNS) gzput(player1.ammo[i]);
gzput(player1.state);
gzputi(bdamage);
bdamage = 0;
gzputi(ddamage);
if (ddamage) {
gzputv(&dorig);
|
|
|
|
|
|
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
if (!demorecording)
return;
gzputi(lastmillis - starttime);
gzputi(len);
gzwrite(f, buf, len);
gzput(extras);
if (extras) {
gzput(player1.gunSelect);
gzput(player1.lastAttackGun);
gzputi(player1.lastAction - starttime);
gzputi(player1.gunWait);
gzputi(player1.health);
gzputi(player1.armour);
gzput(player1.armourType);
loopi(NUMGUNS) gzput(player1.ammo[i]);
gzput(player1.state);
gzputi(bdamage);
bdamage = 0;
gzputi(ddamage);
if (ddamage) {
gzputv(&dorig);
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
DynamicEntity *target = players[democlientnum];
assert(target);
int extras;
// read additional client side state not present in normal
// network stream
if ((extras = gzget())) {
target.gunselect = gzget();
target.lastattackgun = gzget();
target.lastaction = scaletime(gzgeti());
target.gunwait = gzgeti();
target.health = gzgeti();
target.armour = gzgeti();
target.armourtype = gzget();
loopi(NUMGUNS) target.ammo[i] = gzget();
target.state = gzget();
target.lastmove = playbacktime;
if ((bdamage = gzgeti()))
damageblend(bdamage);
if ((ddamage = gzgeti())) {
gzgetv(&dorig);
particle_splash(3, ddamage, 1000, &dorig);
}
// FIXME: set more client state here
}
// insert latest copy of player into history
if (extras &&
(playerhistory.count == 0 ||
playerhistory.lastObject.lastupdate != playbacktime)) {
DynamicEntity *d = [target copy];
d.lastupdate = playbacktime;
if (playerhistory == nil)
playerhistory = [[OFMutableArray alloc] init];
[playerhistory addObject:d];
if (playerhistory.count > 20)
[playerhistory removeObjectAtIndex:0];
}
readdemotime();
}
if (!demoplayback)
return;
int itime = lastmillis - demodelaymsec;
// find 2 positions in history that surround interpolation time point
size_t count = playerhistory.count;
for (ssize_t i = count - 1; i >= 0; i--) {
if (playerhistory[i].lastupdate < itime) {
DynamicEntity *a = playerhistory[i];
DynamicEntity *b = a;
if (i + 1 < playerhistory.count)
b = playerhistory[i + 1];
player1 = b;
// interpolate pos & angles
if (a != b) {
DynamicEntity *c = b;
if (i + 2 < playerhistory.count)
c = playerhistory[i + 2];
DynamicEntity *z = a;
if (i - 1 >= 0)
z = playerhistory[i - 1];
// if(a==z || b==c)
// printf("* %d\n", lastmillis);
float bf = (itime - a.lastupdate) /
(float)(b.lastupdate - a.lastupdate);
fixwrap(a, player1);
fixwrap(c, player1);
fixwrap(z, player1);
vdist(dist, v, z.o, c.o);
// if teleport or spawn, don't interpolate
if (dist < 16) {
catmulrom(
z.o, a.o, b.o, c.o, bf, player1.o);
OFVector3D vz = OFMakeVector3D(
z.yaw, z.pitch, z.roll);
OFVector3D va = OFMakeVector3D(
a.yaw, a.pitch, a.roll);
OFVector3D vb = OFMakeVector3D(
b.yaw, b.pitch, b.roll);
OFVector3D vc = OFMakeVector3D(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
DynamicEntity *target = players[democlientnum];
assert(target);
int extras;
// read additional client side state not present in normal
// network stream
if ((extras = gzget())) {
target.gunSelect = gzget();
target.lastAttackGun = gzget();
target.lastAction = scaletime(gzgeti());
target.gunWait = gzgeti();
target.health = gzgeti();
target.armour = gzgeti();
target.armourType = gzget();
loopi(NUMGUNS) target.ammo[i] = gzget();
target.state = gzget();
target.lastMove = playbacktime;
if ((bdamage = gzgeti()))
damageblend(bdamage);
if ((ddamage = gzgeti())) {
gzgetv(&dorig);
particle_splash(3, ddamage, 1000, &dorig);
}
// FIXME: set more client state here
}
// insert latest copy of player into history
if (extras &&
(playerhistory.count == 0 ||
playerhistory.lastObject.lastUpdate != playbacktime)) {
DynamicEntity *d = [target copy];
d.lastUpdate = playbacktime;
if (playerhistory == nil)
playerhistory = [[OFMutableArray alloc] init];
[playerhistory addObject:d];
if (playerhistory.count > 20)
[playerhistory removeObjectAtIndex:0];
}
readdemotime();
}
if (!demoplayback)
return;
int itime = lastmillis - demodelaymsec;
// find 2 positions in history that surround interpolation time point
size_t count = playerhistory.count;
for (ssize_t i = count - 1; i >= 0; i--) {
if (playerhistory[i].lastUpdate < itime) {
DynamicEntity *a = playerhistory[i];
DynamicEntity *b = a;
if (i + 1 < playerhistory.count)
b = playerhistory[i + 1];
player1 = b;
// interpolate pos & angles
if (a != b) {
DynamicEntity *c = b;
if (i + 2 < playerhistory.count)
c = playerhistory[i + 2];
DynamicEntity *z = a;
if (i - 1 >= 0)
z = playerhistory[i - 1];
// if(a==z || b==c)
// printf("* %d\n", lastmillis);
float bf = (itime - a.lastUpdate) /
(float)(b.lastUpdate - a.lastUpdate);
fixwrap(a, player1);
fixwrap(c, player1);
fixwrap(z, player1);
vdist(dist, v, z.origin, c.origin);
// if teleport or spawn, don't interpolate
if (dist < 16) {
catmulrom(z.origin, a.origin, b.origin,
c.origin, bf, player1.origin);
OFVector3D vz = OFMakeVector3D(
z.yaw, z.pitch, z.roll);
OFVector3D va = OFMakeVector3D(
a.yaw, a.pitch, a.roll);
OFVector3D vb = OFMakeVector3D(
b.yaw, b.pitch, b.roll);
OFVector3D vc = OFMakeVector3D(
|