diff options
author | Alexander Levin <al.le@rockbox.org> | 2009-06-30 20:00:46 +0000 |
---|---|---|
committer | Alexander Levin <al.le@rockbox.org> | 2009-06-30 20:00:46 +0000 |
commit | 6a5245ae08e35bd90436ddb97a8c7fbfea89b1fd (patch) | |
tree | 1238b06f8a88573c3fe0c4a5c31c09892e263306 /apps/plugins/lib/highscore.h | |
parent | e905ca61d4a2d90d9a2fac0ae1b70c55451eaf88 (diff) | |
download | rockbox-6a5245ae08e35bd90436ddb97a8c7fbfea89b1fd.tar.gz rockbox-6a5245ae08e35bd90436ddb97a8c7fbfea89b1fd.zip |
Improve the highscore related functions in plugin lib (FS#10350)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21578 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib/highscore.h')
-rw-r--r-- | apps/plugins/lib/highscore.h | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h index db09172c7d..a38a6f7bf3 100644 --- a/apps/plugins/lib/highscore.h +++ b/apps/plugins/lib/highscore.h | |||
@@ -21,6 +21,8 @@ | |||
21 | #ifndef HIGHSCORE_H | 21 | #ifndef HIGHSCORE_H |
22 | #define HIGHSCORE_H | 22 | #define HIGHSCORE_H |
23 | 23 | ||
24 | /* see rockblox.c for the example of usage. */ | ||
25 | |||
24 | struct highscore | 26 | struct highscore |
25 | { | 27 | { |
26 | char name[32]; | 28 | char name[32]; |
@@ -28,8 +30,56 @@ struct highscore | |||
28 | int level; | 30 | int level; |
29 | }; | 31 | }; |
30 | 32 | ||
33 | /* Saves the scores to a file | ||
34 | * - filename: name of the file to write the data to | ||
35 | * - scores : scores to store | ||
36 | * - num_scores: number of the elements in the array 'scores' | ||
37 | * Returns 0 on success or a negative value if an error occures | ||
38 | */ | ||
31 | int highscore_save(char *filename, struct highscore *scores, int num_scores); | 39 | int highscore_save(char *filename, struct highscore *scores, int num_scores); |
40 | |||
41 | /* Reads the scores from a file. The file must be a text file, each line | ||
42 | * represents a score entry. | ||
43 | * | ||
44 | * - filename: name of the file to read the data from | ||
45 | * - scores : where to put the read data | ||
46 | * - num_scores: max number of the scores to read (array capacity) | ||
47 | * | ||
48 | * Returns 0 on success or a negative value if an error occures | ||
49 | */ | ||
32 | int highscore_load(char *filename, struct highscore *scores, int num_scores); | 50 | int highscore_load(char *filename, struct highscore *scores, int num_scores); |
33 | int highscore_update(int score, int level, struct highscore *scores, int num_scores); | 51 | |
52 | /* Inserts score and level into array of struct highscore in the | ||
53 | * descending order of scores, i.e. higher scores are at lower array | ||
54 | * indexes. | ||
55 | * | ||
56 | * - score : the new score value to insert | ||
57 | * - level : the game level at which the score was reached | ||
58 | * - name : the name of the new entry (whatever it means) | ||
59 | * - scores: the array of scores to insert the new value into | ||
60 | * - num_scores: number of elements in 'scores' | ||
61 | * | ||
62 | * Returns the 0-based position of the newly inserted score if it was | ||
63 | * inserted. Returns a negative value if the score was not inserted | ||
64 | * (i.e. it was less than the lowest score in the array). | ||
65 | */ | ||
66 | int highscore_update(int score, int level, const char *name, | ||
67 | struct highscore *scores, int num_scores); | ||
68 | |||
69 | /* Checks whether the new score would be inserted into the score table. | ||
70 | * This function can be used to find out whether a score with the given | ||
71 | * value would be inserted into the score table. If yes, the program | ||
72 | * can collect the name of the entry from the user (if it's done that | ||
73 | * way) and then really update the score table with 'highscore_update'. | ||
74 | * | ||
75 | * - score : the score value to check | ||
76 | * - scores: the array of existing scores | ||
77 | * - num_scores: number of elements in 'scores' | ||
78 | * | ||
79 | * Returns true iff the given score would be inserted into the score | ||
80 | * table by highscore_update. | ||
81 | */ | ||
82 | bool highscore_would_update(int score, struct highscore *scores, | ||
83 | int num_scores); | ||
34 | 84 | ||
35 | #endif | 85 | #endif |