Index: apps/plugins/brickmania.c =================================================================== --- apps/plugins/brickmania.c (revision 24759) +++ apps/plugins/brickmania.c (working copy) @@ -1018,10 +1018,32 @@ } } +struct game_ctx +{ + int pad_pos_x; + int life; + int game_state; + int pad_type; + int score; + bool flip_sides; + int level; + int brick_on_board; + int used_balls; + int pad_width; + int num_count; + cube brick[80]; + balls ball[MAX_BALLS]; + sfire fire[30]; +}; + static void brickmania_loadgame(void) { int fd; + int i; + struct game_ctx state; + rb->memset(&state, 0, sizeof(state)); + resume = false; /* open game file */ @@ -1029,6 +1051,8 @@ if(fd < 0) return; /* read in saved game */ + if(rb->read(fd, &state, sizeof(struct game_ctx)) <= 0) +#if 0 if((rb->read(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) || (rb->read(fd, &life, sizeof(life)) <= 0) || (rb->read(fd, &game_state, sizeof(game_state)) <= 0) || @@ -1043,6 +1067,7 @@ (rb->read(fd, &brick, sizeof(brick)) <= 0) || (rb->read(fd, &ball, sizeof(ball)) <= 0) || (rb->read(fd, &fire, sizeof(fire)) <= 0)) +#endif { rb->splash(HZ/2, "Failed to load game"); } @@ -1054,17 +1079,59 @@ rb->close(fd); + pad_pos_x = state.pad_pos_x; + life = state.life; + game_state = state.game_state; + pad_type = state.pad_type; + score = state.score; + flip_sides = state.flip_sides; + level = state.level; + brick_on_board = state.brick_on_board; + used_balls = state.used_balls; + pad_width = state.pad_width; + num_count = state.num_count; + for (i=0;i<80;i++) + brick[i] = state.brick[i]; + for (i=0;imemset(&state, 0, sizeof(state)); + + state.pad_pos_x = pad_pos_x; + state.life = life; + state.game_state = game_state; + state.pad_type = pad_type; + state.score = score; + state.flip_sides = flip_sides; + state.level = level; + state.brick_on_board = brick_on_board; + state.used_balls = used_balls; + state.pad_width = pad_width; + state.num_count = num_count; + for (i=0;i<80;i++) + state.brick[i] = brick[i]; + for (i=0;iopen(SAVE_FILE, O_WRONLY|O_CREAT); if(fd < 0) return; + if(rb->write(fd, &state, sizeof(struct game_ctx)) <= 0) +#if 0 if ((rb->write(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) || (rb->write(fd, &life, sizeof(life)) <= 0) || (rb->write(fd, &game_state, sizeof(game_state)) <= 0) || @@ -1079,6 +1146,7 @@ (rb->write(fd, &brick, sizeof(brick)) <= 0) || (rb->write(fd, &ball, sizeof(ball)) <= 0) || (rb->write(fd, &fire, sizeof(fire)) <= 0)) +#endif { rb->close(fd); rb->remove(SAVE_FILE);