Save system
This commit is contained in:
parent
25ca36ea50
commit
a665f12807
BIN
Plague.g1a
BIN
Plague.g1a
Binary file not shown.
16
src/save.c
16
src/save.c
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue