Save system

This commit is contained in:
Shadow15510 2021-06-03 22:09:24 +02:00
parent 25ca36ea50
commit a665f12807
2 changed files with 13 additions and 3 deletions

Binary file not shown.

View File

@ -14,7 +14,13 @@ void read_save(struct game *current_game)
uint16_t foundpath[30];
// Sizes of data
const int planes_size = sizeof(*current_game->planes);
const int planes_size = sizeof(*current_game->planes) * (NB_PLANES + 1);
struct plane *new_planes[NB_PLANES + 1];
for (int i = 0; i < NB_PLANES; i ++)
{
new_planes[i] = current_game->planes[i];
}
const int data_size = current_game->grid.width * current_game->grid.height;
uint8_t *data = current_game->grid.data;
@ -33,14 +39,18 @@ void read_save(struct game *current_game)
else
{
fd = BFile_Open(filename, BFile_ReadOnly);
BFile_Read(fd, current_game, sizeof(*current_game), 0);
for (int i = 0; i < NB_PLANES; i ++)
{
current_game->planes[i] = new_planes[i];
}
for (int i = 0; i < NB_PLANES; i ++)
{
BFile_Read(fd, current_game->planes[i], sizeof(struct plane), -1);
}
BFile_Read(fd, data, data_size, -1);
BFile_Close(fd);
current_game->grid.data = data;