-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced data cache for faster loading
- Loading branch information
1 parent
bfff7f6
commit a77bd93
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef DAtA_CACHE_H | ||
#define DAtA_CACHE_H | ||
#define CACHE_FILE_VERSION 0 | ||
#include <3ds.h> | ||
|
||
void update_data_cache(u8 game, u8 multiplayer, const char* level_names); | ||
u8 read_data_cache(u8 game, u8 multiplayer, char* level_names); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <stdio.h> | ||
#include "data_cache.h" | ||
#include "gamespecific.h" | ||
#include "settings.h" | ||
|
||
void update_data_cache(u8 game, u8 multiplayer, const char* level_names) { | ||
u8 version = CACHE_FILE_VERSION; | ||
char cachefilename[64]; | ||
u16 num_of_levels = 0; | ||
if (!level_names) { | ||
return; | ||
} | ||
if (!multiplayer) { | ||
num_of_levels = (u16)import[game].num_of_difficulties | ||
* (u16)import[game].num_of_level_per_difficulty; | ||
}else{ | ||
return; | ||
} | ||
sprintf(cachefilename, "%s/CACHE_%02X.DAT",PATH_ROOT, game + (multiplayer?0x80:0)); | ||
FILE* cachefile = fopen(cachefilename, "wb"); | ||
if (!cachefile) { | ||
return; | ||
} | ||
fwrite(&version, 1, 1, cachefile); | ||
fwrite(level_names, 1, 33*num_of_levels, cachefile); | ||
fclose(cachefile); | ||
} | ||
|
||
u8 read_data_cache(u8 game, u8 multiplayer, char* level_names) { | ||
u8 version = 0; | ||
char cachefilename[64]; | ||
u16 num_of_levels = 0; | ||
if (!level_names) { | ||
return 0; | ||
} | ||
if (!multiplayer) { | ||
num_of_levels = (u16)import[game].num_of_difficulties | ||
* (u16)import[game].num_of_level_per_difficulty; | ||
}else{ | ||
return 0; | ||
} | ||
sprintf(cachefilename, "%s/CACHE_%02X.DAT",PATH_ROOT, game + (multiplayer?0x80:0)); | ||
FILE* cachefile = fopen(cachefilename, "rb"); | ||
if (!cachefile) { | ||
return 0; | ||
} | ||
fread(&version, 1, 1, cachefile); | ||
if (version > CACHE_FILE_VERSION) { | ||
return 0; | ||
} | ||
u16 size = fread(level_names, 1, 33*num_of_levels, cachefile); | ||
fclose(cachefile); | ||
if (size != 33*num_of_levels) { | ||
return 0; | ||
} | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters