Fix bugs
This commit is contained in:
parent
8f94797d9c
commit
14796097e8
14
src/save.c
14
src/save.c
|
@ -14,6 +14,9 @@ void read_save(struct game *current_game)
|
|||
uint16_t foundpath[30];
|
||||
|
||||
// Sizes of data
|
||||
const int planes_size = sizeof(*current_game->planes);
|
||||
struct plane *planes = current_game->planes;
|
||||
|
||||
const int data_size = current_game->grid.width * current_game->grid.height;
|
||||
uint8_t *data = current_game->grid.data;
|
||||
|
||||
|
@ -24,7 +27,7 @@ void read_save(struct game *current_game)
|
|||
// If file doesn't exists
|
||||
if (checkfile == -1)
|
||||
{
|
||||
int size = sizeof(*current_game) + data_size;
|
||||
int size = sizeof(*current_game) + planes_size + data_size;
|
||||
BFile_Create(filename, BFile_File, &size);
|
||||
}
|
||||
|
||||
|
@ -32,9 +35,14 @@ void read_save(struct game *current_game)
|
|||
else
|
||||
{
|
||||
fd = BFile_Open(filename, BFile_ReadOnly);
|
||||
|
||||
BFile_Read(fd, current_game, sizeof(*current_game), 0);
|
||||
Bfile_Read(fd, planes, planes_size, -1);
|
||||
BFile_Read(fd, data, data_size, -1);
|
||||
|
||||
BFile_Close(fd);
|
||||
|
||||
current_game->planes = planes;
|
||||
current_game->grid.data = data;
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +55,15 @@ void write_save(const struct game *current_game)
|
|||
|
||||
// Create a new savefile
|
||||
const int data_size = current_game->grid.width * current_game->grid.height;
|
||||
int size = sizeof(*current_game) + data_size;
|
||||
const int planes_size = sizeof(*current_game->planes);
|
||||
int size = sizeof(*current_game) + planes_size + data_size;
|
||||
|
||||
BFile_Remove(filename);
|
||||
BFile_Create(filename, BFile_File, &size);
|
||||
|
||||
// Write data
|
||||
BFile_Write(fd, current_game, sizeof(*current_game));
|
||||
BFile_Write(fd, current_game->planes, planes_size);
|
||||
BFile_Write(fd, current_game->grid.data, data_size);
|
||||
|
||||
// Close file
|
||||
|
|
Loading…
Reference in New Issue