Eliminated floating point values from replays for portability
Player power is now internally an integer. There is no good reason to use floating point math there. Stored as an uint16 in replays. Player coordinates are now floored when a stage starts. This is unnoticable to the player. Stored as a pair of uint16s in replays.
This commit is contained in:
parent
488c1d1665
commit
d0377bd537
9 changed files with 51 additions and 47 deletions
|
@ -59,7 +59,7 @@ enum {
|
|||
DEATHBOMB_TIME = 10,
|
||||
DEATH_DELAY = 70,
|
||||
|
||||
PLR_MAXPOWER = 4,
|
||||
PLR_MAXPOWER = 400,
|
||||
PLR_START_LIVES = 2,
|
||||
PLR_START_BOMBS = 3,
|
||||
MAX_CONTINUES = 3,
|
||||
|
|
|
@ -90,7 +90,7 @@ void process_items(void) {
|
|||
if(v == 1) {
|
||||
switch(item->type) {
|
||||
case Power:
|
||||
player_set_power(&global.plr, global.plr.power + 0.03);
|
||||
player_set_power(&global.plr, global.plr.power + 3);
|
||||
break;
|
||||
case Point:
|
||||
global.points += 100;
|
||||
|
|
|
@ -38,7 +38,7 @@ Animation *player_get_ani(Character cha) {
|
|||
return ani;
|
||||
}
|
||||
|
||||
void player_set_power(Player *plr, float npow) {
|
||||
void player_set_power(Player *plr, short npow) {
|
||||
switch(plr->cha) {
|
||||
case Youmu:
|
||||
youmu_power(plr, npow);
|
||||
|
|
|
@ -43,7 +43,7 @@ typedef struct {
|
|||
short moving;
|
||||
|
||||
short dir;
|
||||
float power;
|
||||
short power;
|
||||
int graze;
|
||||
|
||||
int lifes;
|
||||
|
@ -76,7 +76,7 @@ void player_draw(Player*);
|
|||
void player_logic(Player*);
|
||||
|
||||
void player_set_char(Player*, Character);
|
||||
void player_set_power(Player *plr, float npow);
|
||||
void player_set_power(Player *plr, short npow);
|
||||
|
||||
void player_move(Player*, complex delta);
|
||||
|
||||
|
|
|
@ -172,13 +172,13 @@ int youmu_opposite_myon(Enemy *e, int t) {
|
|||
if(plr->fire && !(global.frames % 6) && global.plr.deathtime >= -1) {
|
||||
int a = 20;
|
||||
|
||||
if(plr->power >= 3) {
|
||||
if(plr->power >= 300) {
|
||||
a = 13;
|
||||
create_projectile1c("hghost", e->pos, NULL, linear, -21*cexp(I*(carg(-e->pos0)+0.1)))->type = PlrProj+45;
|
||||
create_projectile1c("hghost", e->pos, NULL, linear, -21*cexp(I*(carg(-e->pos0)-0.1)))->type = PlrProj+45;
|
||||
}
|
||||
|
||||
create_projectile1c("hghost", e->pos, NULL, linear, -21*cexp(I*carg(-e->pos0)))->type = PlrProj+(60+a*(int)plr->power);
|
||||
create_projectile1c("hghost", e->pos, NULL, linear, -21*cexp(I*carg(-e->pos0)))->type = PlrProj+(60+a*(plr->power/100));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -237,10 +237,10 @@ void youmu_shot(Player *plr) {
|
|||
if(ref == -1)
|
||||
ref = add_ref(NULL);
|
||||
|
||||
create_projectile2c("youhoming", plr->pos, NULL, youmu_homing, -3.0I, ref)->type = PlrProj+(450+225*((int)plr->power));
|
||||
create_projectile2c("youhoming", plr->pos, NULL, youmu_homing, -3.0I, ref)->type = PlrProj+(450+225*(plr->power/100));
|
||||
}
|
||||
|
||||
if(!plr->focus && !(global.frames % (int)round(8-plr->power*1.3))) {
|
||||
if(!plr->focus && !(global.frames % (int)round(8 - (plr->power / 100.0) * 1.3))) {
|
||||
create_projectile2c("hghost", plr->pos, NULL, accelerated, 2-10.0I, -0.4I)->type = PlrProj+27;
|
||||
create_projectile2c("hghost", plr->pos, NULL, accelerated, -10.0I, -0.4I)->type = PlrProj+27;
|
||||
create_projectile2c("hghost", plr->pos, NULL, accelerated, -2-10.0I, -0.4I)->type = PlrProj+27;
|
||||
|
@ -264,7 +264,7 @@ void youmu_bomb(Player *plr) {
|
|||
}
|
||||
}
|
||||
|
||||
void youmu_power(Player *plr, float npow) {
|
||||
void youmu_power(Player *plr, short npow) {
|
||||
if(plr->shot == YoumuOpposite && plr->slaves == NULL)
|
||||
create_enemy_p(&plr->slaves, 40.0I, ENEMY_IMMUNE, YoumuOppositeMyon, youmu_opposite_myon, 0, 0, 0, 0);
|
||||
}
|
||||
|
@ -498,10 +498,10 @@ void marisa_bomb(Player *plr) {
|
|||
}
|
||||
}
|
||||
|
||||
void marisa_power(Player *plr, float npow) {
|
||||
void marisa_power(Player *plr, short npow) {
|
||||
Enemy *e = plr->slaves, *tmp;
|
||||
|
||||
if((int)plr->power == (int)npow)
|
||||
if(plr->power / 100 == npow / 100)
|
||||
return;
|
||||
|
||||
while(e != 0) {
|
||||
|
@ -510,38 +510,43 @@ void marisa_power(Player *plr, float npow) {
|
|||
if(tmp->hp == ENEMY_IMMUNE)
|
||||
delete_enemy(&plr->slaves, tmp);
|
||||
}
|
||||
|
||||
|
||||
switch(plr->shot) {
|
||||
case MarisaLaser:
|
||||
if((int)npow == 1)
|
||||
if(npow / 100 == 1) {
|
||||
create_enemy_p(&plr->slaves, -40.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -40.0I, 5, 0, 0);
|
||||
}
|
||||
|
||||
if(npow >= 2) {
|
||||
if(npow >= 200) {
|
||||
create_enemy_p(&plr->slaves, 25-5.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, 8-40.0I, 5, M_PI/30, 0);
|
||||
create_enemy_p(&plr->slaves, -25-5.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -8-40.0I, 5, -M_PI/30, 0);
|
||||
}
|
||||
|
||||
if((int)npow == 3)
|
||||
if(npow / 100 == 3) {
|
||||
create_enemy_p(&plr->slaves, -30.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -50.0I, 5, 0, 0);
|
||||
}
|
||||
|
||||
if(npow >= 4) {
|
||||
if(npow >= 400) {
|
||||
create_enemy_p(&plr->slaves, 17-30.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, 4-45.0I, 5, 0, 0);
|
||||
create_enemy_p(&plr->slaves, -17-30.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_laser_slave, -4-45.0I, 5, 0, 0);
|
||||
}
|
||||
break;
|
||||
case MarisaStar:
|
||||
if((int)npow == 1)
|
||||
if(npow / 100 == 1) {
|
||||
create_enemy_p(&plr->slaves, 40.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, +30.0I, -2.0I, -0.1I, 5);
|
||||
}
|
||||
|
||||
if(npow >= 2) {
|
||||
if(npow >= 200) {
|
||||
double side = npow == 4? 0 : 0.3;
|
||||
create_enemy_p(&plr->slaves, 30.0I+15, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, +30.0I+10, -side-2.0I, -0.1I, 5);
|
||||
create_enemy_p(&plr->slaves, 30.0I-15, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, +30.0I-10, side-2.0I, -0.1I, 5);
|
||||
}
|
||||
|
||||
if((int)npow == 3)
|
||||
if(npow / 100 == 3) {
|
||||
create_enemy_p(&plr->slaves, -30.0I, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, +30.0I, -2.0I, -0.1I, 5);
|
||||
if(npow >= 4) {
|
||||
}
|
||||
|
||||
if(npow >= 400) {
|
||||
create_enemy_p(&plr->slaves, 30, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, 25+30.0I, -0.5-2.0I, -0.1I, 5);
|
||||
create_enemy_p(&plr->slaves, -30, ENEMY_IMMUNE, MariLaserSlave, marisa_star_slave, -25+30.0I, 0.5-2.0I, -0.1I, 5);
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ int youmu_homing(Projectile *p, int t);
|
|||
|
||||
void youmu_shot(Player *plr);
|
||||
void youmu_bomb(Player *plr);
|
||||
void youmu_power(Player *plr, float npow);
|
||||
void youmu_power(Player *plr, short npow);
|
||||
|
||||
/* Marisa */
|
||||
|
||||
void marisa_shot(Player *plr);
|
||||
void marisa_bomb(Player *plr);
|
||||
void marisa_power(Player *plr, float npow);
|
||||
void marisa_power(Player *plr, short npow);
|
||||
|
||||
/* Misc */
|
||||
int plrmode_repr(char *out, size_t outsize, Character pchar, ShotMode pshot);
|
||||
|
|
19
src/replay.c
19
src/replay.c
|
@ -11,6 +11,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "paths/native.h"
|
||||
|
@ -45,8 +46,8 @@ ReplayStage* replay_init_stage(Replay *rpy, StageInfo *stage, uint64_t seed, Pla
|
|||
s->diff = global.diff;
|
||||
s->points = global.points;
|
||||
|
||||
s->plr_pos_x._double = creal(plr->pos);
|
||||
s->plr_pos_y._double = cimag(plr->pos);
|
||||
s->plr_pos_x = floor(creal(plr->pos));
|
||||
s->plr_pos_y = floor(cimag(plr->pos));
|
||||
|
||||
s->plr_focus = plr->focus;
|
||||
s->plr_fire = plr->fire;
|
||||
|
@ -54,7 +55,7 @@ ReplayStage* replay_init_stage(Replay *rpy, StageInfo *stage, uint64_t seed, Pla
|
|||
s->plr_shot = plr->shot;
|
||||
s->plr_lifes = plr->lifes;
|
||||
s->plr_bombs = plr->bombs;
|
||||
s->plr_power._double = plr->power;
|
||||
s->plr_power = plr->power;
|
||||
s->plr_moveflags = plr->moveflags;
|
||||
|
||||
printf("replay_init_stage(): created a new stage for writting\n");
|
||||
|
@ -135,11 +136,11 @@ int replay_write_stage(ReplayStage *stg, SDL_RWops *file) {
|
|||
SDL_WriteLE32(file, stg->points);
|
||||
SDL_WriteU8(file, stg->plr_char);
|
||||
SDL_WriteU8(file, stg->plr_shot);
|
||||
SDL_WriteLE64(file, stg->plr_pos_x._int);
|
||||
SDL_WriteLE64(file, stg->plr_pos_y._int);
|
||||
SDL_WriteLE16(file, stg->plr_pos_x);
|
||||
SDL_WriteLE16(file, stg->plr_pos_y);
|
||||
SDL_WriteU8(file, stg->plr_focus);
|
||||
SDL_WriteU8(file, stg->plr_fire);
|
||||
SDL_WriteLE64(file, stg->plr_power._int);
|
||||
SDL_WriteLE16(file, stg->plr_power);
|
||||
SDL_WriteU8(file, stg->plr_lifes);
|
||||
SDL_WriteU8(file, stg->plr_bombs);
|
||||
SDL_WriteU8(file, stg->plr_moveflags);
|
||||
|
@ -224,11 +225,11 @@ int replay_read(Replay *rpy, SDL_RWops *file) {
|
|||
stg->points = SDL_ReadLE32(file);
|
||||
stg->plr_char = SDL_ReadU8(file);
|
||||
stg->plr_shot = SDL_ReadU8(file);
|
||||
stg->plr_pos_x._int = SDL_ReadLE64(file);
|
||||
stg->plr_pos_y._int = SDL_ReadLE64(file);
|
||||
stg->plr_pos_x = SDL_ReadLE16(file);
|
||||
stg->plr_pos_y = SDL_ReadLE16(file);
|
||||
stg->plr_focus = SDL_ReadU8(file);
|
||||
stg->plr_fire = SDL_ReadU8(file);
|
||||
stg->plr_power._int = SDL_ReadLE64(file);
|
||||
stg->plr_power = SDL_ReadLE16(file);
|
||||
stg->plr_lifes = SDL_ReadU8(file);
|
||||
stg->plr_bombs = SDL_ReadU8(file);
|
||||
stg->plr_moveflags = SDL_ReadU8(file);
|
||||
|
|
15
src/replay.h
15
src/replay.h
|
@ -15,20 +15,13 @@
|
|||
#define REPLAY_ALLOC_INITIAL 1000
|
||||
#define REPLAY_ALLOC_ADDITIONAL 500
|
||||
#define REPLAY_EXTENSION "tsr"
|
||||
#define REPLAY_STRUCT_VERSION 0
|
||||
#define REPLAY_STRUCT_VERSION 1
|
||||
#define REPLAY_MAX_NAME_LENGTH 128
|
||||
|
||||
#ifdef DEBUG
|
||||
#define REPLAY_WRITE_DESYNC_CHECKS
|
||||
#endif
|
||||
|
||||
typedef union float64_u {
|
||||
// ASSUMPTION: the "double" type is an IEEE 754 binary64
|
||||
|
||||
double _double;
|
||||
uint64_t _int;
|
||||
} float64_u;
|
||||
|
||||
typedef struct ReplayEvent {
|
||||
uint32_t frame;
|
||||
uint8_t type;
|
||||
|
@ -45,11 +38,11 @@ typedef struct ReplayStage {
|
|||
// initial player settings
|
||||
uint8_t plr_char;
|
||||
uint8_t plr_shot;
|
||||
float64_u plr_pos_x;
|
||||
float64_u plr_pos_y;
|
||||
uint16_t plr_pos_x;
|
||||
uint16_t plr_pos_y;
|
||||
uint8_t plr_focus;
|
||||
uint8_t plr_fire;
|
||||
float64_u plr_power;
|
||||
uint16_t plr_power;
|
||||
uint8_t plr_lifes;
|
||||
uint8_t plr_bombs;
|
||||
uint8_t plr_moveflags;
|
||||
|
|
13
src/stage.c
13
src/stage.c
|
@ -203,7 +203,7 @@ void draw_hud(void) {
|
|||
for(i = 0; i < global.plr.bombs; i++)
|
||||
draw_texture(16*i,200, "star");
|
||||
|
||||
sprintf(buf, "%.2f", global.plr.power);
|
||||
sprintf(buf, "%.2f", global.plr.power / 100.0);
|
||||
draw_text(AL_Center, 10, 236, buf, _fonts.standard);
|
||||
|
||||
sprintf(buf, "%i", global.plr.graze);
|
||||
|
@ -473,6 +473,11 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
|
|||
if(global.replay.active)
|
||||
replay_init_stage(&global.replay, info, seed, &global.plr);
|
||||
printf("Random seed: %u\n", seed);
|
||||
|
||||
// match replay format
|
||||
uint16_t px = floor(creal(global.plr.pos));
|
||||
uint16_t py = floor(cimag(global.plr.pos));
|
||||
global.plr.pos = px + I * py;
|
||||
} else {
|
||||
ReplayStage *stg = global.replay.current;
|
||||
printf("REPLAY_PLAY mode: %d events, stage: \"%s\"\n", stg->ecount, stage_get(stg->stage)->title);
|
||||
|
@ -485,19 +490,19 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
|
|||
|
||||
global.plr.shot = stg->plr_shot;
|
||||
global.plr.cha = stg->plr_char;
|
||||
global.plr.pos = stg->plr_pos_x._double + I * stg->plr_pos_y._double;
|
||||
global.plr.pos = stg->plr_pos_x + I * stg->plr_pos_y;
|
||||
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._double;
|
||||
global.plr.power = stg->plr_power;
|
||||
global.plr.moveflags = stg->plr_moveflags;
|
||||
|
||||
stg->playpos = 0;
|
||||
}
|
||||
|
||||
Enemy *e = global.plr.slaves, *tmp;
|
||||
float power = global.plr.power;
|
||||
short power = global.plr.power;
|
||||
global.plr.power = -1;
|
||||
|
||||
while(e != 0) {
|
||||
|
|
Loading…
Reference in a new issue