Hopefully fixed the replay desync disaster. I'm going to have nightmares about it. Needs more testing.

This commit is contained in:
Andrew "Akari" Alexeyew 2012-08-07 03:45:38 +03:00
parent 385c292606
commit f2cf436ffa
8 changed files with 50 additions and 35 deletions

View file

@ -43,10 +43,12 @@ Enemy *create_enemy_p(Enemy **enemies, complex pos, int hp, EnemyDrawRule draw_r
void _delete_enemy(void **enemies, void* enemy) {
Enemy *e = (Enemy *)enemy;
if(e->hp <= 0 && e->hp > ENEMY_IMMUNE) {
if(e->hp <= 0 && e->hp > ENEMY_IMMUNE && !e->is_playerslave) {
int i;
for(i = 0; i < 10; i++)
create_particle2c("flare", e->pos, NULL, Fade, timeout_linear, 10, (3+frand()*10)*cexp(I*frand()*2*M_PI));
for(i = 0; i < 10; i++) {
tsrand_fill(2);
create_particle2c("flare", e->pos, NULL, Fade, timeout_linear, 10, (3+afrand(0)*10)*cexp(I*afrand(1)*2*M_PI));
}
create_particle1c("blast", e->pos, NULL, Blast, timeout, 20);
create_particle1c("blast", e->pos, NULL, Blast, timeout, 20);
create_particle2c("blast", e->pos, NULL, GrowFade, timeout, 15,0);

View file

@ -44,6 +44,7 @@ struct Enemy {
complex args[RULE_ARGC];
float alpha;
int is_playerslave;
};
#define create_enemy4c(p,h,d,l,a1,a2,a3,a4) create_enemy_p(&global.enemies,p,h,d,l,a1,a2,a3,a4)

View file

@ -25,7 +25,7 @@ static int pickedstage;
void start_replay(void *arg) {
ReplayStage *rstg;
StageInfo *gstg;
int i;
int i, pinit = False;
replay_copy(&global.replay, (Replay*)arg);
global.replaymode = REPLAY_PLAY;
@ -43,7 +43,11 @@ void start_replay(void *arg) {
continue;
}
init_player(&global.plr);
if(!pinit) {
init_player(&global.plr);
pinit = True;
}
gstg->loop();
if(global.game_over == GAMEOVER_ABORT)

View file

@ -221,8 +221,10 @@ void player_realdeath(Player *plr) {
void player_death(Player *plr) {
if(plr->deathtime == -1 && global.frames - abs(plr->recovery) > 0) {
int i;
for(i = 0; i < 20; i++)
create_particle2c("flare", plr->pos, NULL, Shrink, timeout_linear, 40, (3+frand()*7)*cexp(I*tsrand()));
for(i = 0; i < 20; i++) {
tsrand_fill(2);
create_particle2c("flare", plr->pos, NULL, Shrink, timeout_linear, 40, (3+afrand(0)*7)*cexp(I*tsrand_a(1)));
}
create_particle2c("blast", plr->pos, rgb(1,0.5,0.3), GrowFade, timeout, 35, 2.4);
plr->deathtime = global.frames + DEATHBOMB_TIME;
}

View file

@ -214,17 +214,17 @@ void youmu_shot(Player *plr) {
}
if(plr->shot == YoumuOpposite && plr->slaves == NULL)
create_enemy_p(&plr->slaves, 40I, ENEMY_IMMUNE, YoumuOppositeMyon, youmu_opposite_myon, 0, 0, 0, 0);
create_enemy_p(&plr->slaves, 40I, ENEMY_IMMUNE, YoumuOppositeMyon, youmu_opposite_myon, 0, 0, 0, 0)->is_playerslave = True;
}
void youmu_bomb(Player *plr) {
switch(plr->shot) {
case YoumuOpposite:
create_enemy_p(&plr->slaves, 40I, ENEMY_BOMB, NULL, youmu_split, 280,0,0,0);
create_enemy_p(&plr->slaves, 40I, ENEMY_BOMB, NULL, youmu_split, 280,0,0,0)->is_playerslave = True;
break;
case YoumuHoming:
create_enemy_p(&plr->slaves, 40I, ENEMY_BOMB, YoumuSlash, youmu_slash, 280,0,0,0);
create_enemy_p(&plr->slaves, 40I, ENEMY_BOMB, YoumuSlash, youmu_slash, 280,0,0,0)->is_playerslave = True;
break;
}
}
@ -418,7 +418,7 @@ void marisa_bomb(Player *plr) {
switch(plr->shot) {
case MarisaLaser:
play_sound("masterspark");
create_enemy_p(&plr->slaves, 40I, ENEMY_BOMB, MasterSpark, master_spark, 280,0,0,0);
create_enemy_p(&plr->slaves, 40I, ENEMY_BOMB, MasterSpark, master_spark, 280,0,0,0)->is_playerslave = True;
break;
case MarisaStar:
for(i = 0; i < 20; i++) {
@ -448,35 +448,35 @@ void marisa_power(Player *plr, float npow) {
switch(plr->shot) {
case MarisaLaser:
if((int)npow == 1)
create_enemy_p(&plr->slaves, -40I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -40I,5,0,0);
create_enemy_p(&plr->slaves, -40I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -40I,5,0,0)->is_playerslave = True;
if(npow >= 2) {
create_enemy_p(&plr->slaves, 25-5I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, 8-40I,5,0,0);
create_enemy_p(&plr->slaves, -25-5I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -8-40I,5,0,0);
create_enemy_p(&plr->slaves, 25-5I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, 8-40I,5,0,0)->is_playerslave = True;
create_enemy_p(&plr->slaves, -25-5I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -8-40I,5,0,0)->is_playerslave = True;
}
if((int)npow == 3)
create_enemy_p(&plr->slaves, -30I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -50I,5,0,0);
create_enemy_p(&plr->slaves, -30I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -50I,5,0,0)->is_playerslave = True;
if(npow >= 4) {
create_enemy_p(&plr->slaves, 17-30I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, 4-45I,5,0,0);
create_enemy_p(&plr->slaves, -17-30I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -4-45I,5,0,0);
create_enemy_p(&plr->slaves, 17-30I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, 4-45I,5,0,0)->is_playerslave = True;
create_enemy_p(&plr->slaves, -17-30I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -4-45I,5,0,0)->is_playerslave = True;
}
break;
case MarisaStar:
if((int)npow == 1)
create_enemy_p(&plr->slaves, 40I, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I, -2I, -0.1I, 5);
create_enemy_p(&plr->slaves, 40I, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I, -2I, -0.1I, 5)->is_playerslave = True;
if(npow >= 2) {
create_enemy_p(&plr->slaves, 30I+15, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I+10, -2I, -0.1I, 5);
create_enemy_p(&plr->slaves, 30I-15, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I-10, -2I, -0.1I, 5);
create_enemy_p(&plr->slaves, 30I+15, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I+10, -2I, -0.1I, 5)->is_playerslave = True;
create_enemy_p(&plr->slaves, 30I-15, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I-10, -2I, -0.1I, 5)->is_playerslave = True;
}
if((int)npow == 3)
create_enemy_p(&plr->slaves, -30I, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I, -2I, -0.1I, 5);
create_enemy_p(&plr->slaves, -30I, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -30I, -2I, -0.1I, 5)->is_playerslave = True;
if(npow >= 4) {
create_enemy_p(&plr->slaves, 30, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, 25, -1-2I, -0.1I, 5);
create_enemy_p(&plr->slaves, -30, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -25, 1-2I, -0.1I, 5);
create_enemy_p(&plr->slaves, 30, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, 25, -1-2I, -0.1I, 5)->is_playerslave = True;
create_enemy_p(&plr->slaves, -30, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -25, 1-2I, -0.1I, 5)->is_playerslave = True;
}
break;
}

View file

@ -45,6 +45,7 @@ ReplayStage* replay_init_stage(Replay *rpy, StageInfo *stage, int seed, Player *
s->plr_lifes = plr->lifes;
s->plr_bombs = plr->bombs;
s->plr_power = plr->power;
s->plr_mflags = plr->moveflags;
printf("replay_init_stage(): created a new stage for writting\n");
replay_select(rpy, rpy->stgcount-1);
@ -153,6 +154,7 @@ int replay_write(Replay *rpy, FILE *file) {
replay_write_double(file, stg->plr_power);
replay_write_int(file, stg->plr_lifes);
replay_write_int(file, stg->plr_bombs);
replay_write_int(file, stg->plr_mflags);
// events
replay_write_int(file, stg->ecount);
@ -192,6 +194,7 @@ enum {
RPY_P_POWER,
RPY_P_LIFES,
RPY_P_BOMBS,
RPY_P_MFLAGS,
// events
RPY_E_COUNT,
@ -262,6 +265,7 @@ int replay_read(Replay *rpy, FILE *file) {
case RPY_P_POWER: s->plr_power = FLOATOF(buf); break;
case RPY_P_LIFES: s->plr_lifes = INTOF(buf); break;
case RPY_P_BOMBS: s->plr_bombs = INTOF(buf); break;
case RPY_P_MFLAGS: s->plr_mflags = INTOF(buf); break;
case RPY_E_COUNT:
s->capacity = s->ecount = INTOF(buf);

View file

@ -34,6 +34,7 @@ typedef struct ReplayStage {
float plr_power;
int plr_lifes;
int plr_bombs;
int plr_mflags;
// events
ReplayEvent *events;

View file

@ -458,7 +458,9 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
}
int seed = time(0);
tsrand_switch(&global.rand_game);
tsrand_seed_p(&global.rand_game, seed);
stage_start();
if(global.replaymode == REPLAY_RECORD) {
if(global.replay.active)
@ -471,17 +473,18 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
tsrand_seed_p(&global.rand_game, stg->seed);
printf("Random seed: %d\n", stg->seed);
global.diff = stg->diff;
global.points = stg->points;
global.diff = stg->diff;
global.points = stg->points;
global.plr.shot = stg->plr_shot;
global.plr.cha = stg->plr_char;
global.plr.pos = stg->plr_pos;
global.plr.focus = stg->plr_focus;
global.plr.fire = stg->plr_fire;
global.plr.lifes = stg->plr_lifes;
global.plr.bombs = stg->plr_bombs;
global.plr.power = stg->plr_power;
global.plr.shot = stg->plr_shot;
global.plr.cha = stg->plr_char;
global.plr.pos = stg->plr_pos;
global.plr.focus = stg->plr_focus;
global.plr.fire = stg->plr_fire;
global.plr.lifes = stg->plr_lifes;
global.plr.bombs = stg->plr_bombs;
global.plr.power = stg->plr_power;
global.plr.moveflags = stg->plr_mflags;
stg->playpos = 0;
}
@ -491,8 +494,6 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
killall(global.plr.slaves);
player_set_power(&global.plr, power);
tsrand_switch(&global.rand_game);
stage_start();
start();
SDL_EnableKeyRepeat(0, 0);